Guide To Setting Up Fetchmail On Yunohost

I followed a setup similar to what @benou describes here, using an external webmail provider as a “second backup mailbox” for my yunohost email, in my case I am using Migadu.

This is a post to share what I did, in case others are searching for how to do the same.

I setup three MX records with my DNS provider, the first MX record points to my yunohost server and has priority 10, the second MX record points to the webmail server with priority 20, and the third MX record points to the backup webmail server with priority 30.

I tested that indeed, on yunohost, when I run ‘service postfix stop’, and send myself an email from another email account elsewhere, the email gets delivered to my webmail (it is working as a backup receiver).

I then wanted to add a fetchmail process, that would regularly fetch the mails from the webmail provider, and bring them into yunohost, so all my email are in one place, and in case some email accidentally got delivered to the webmail for some reason (and I wouldn’t want to miss it).

I tried to follow this guide, but I had some issues with it, so here is what I did.

I am running Yunohost on Debian 10, here are the steps I followed:

Install fetchmail:
apt-get install fetchmail

Create the vmail home folder:
mkdir /var/vmail

Add the following contents to /var/vmail/.fetchmailrc

poll with proto imap port 993
user "youremail" there with password "yourpassword" is "youryunohostusername" here
mda "/usr/lib/dovecot/deliver -d %T" nokeep

For multiple email addresses, you can add multiple lines to .fetchmailrc exactly like above for each of your emails.

Update permissions:
chown -R vmail /var/vmail

Test that its working by running,
sudo -u vmail fetchmail -v --all

You should see it connect, your emails in your webmail should now be empty, and they should all be in your yunohost email.

Create a crontab to regularly run fetchmail.
crontab -u vmail -e

*/15 * * * * * fetchmail -v --all > /var/vmail/fetchmail.log

What I like about this setup, is that my email goes directly to yunohost if everything is working, but if there is a bug, or my server goes down for some period, or I’m travelling and don’t have time to fix something, emails will still go to the backup, and I can sleep easy.

Hope this is helpful to someone! Or share any feedback. It could also be interesting to add a yunohost command or GUI interface for setting this up, similar to the way there is a yunohost command for configuring an outgoing SMTP relay.


Good guide!
For what it’s worth, an alternative to crontab is to use the daemon mode of fetchmail, eg.

cat > /etc/fetchmailrc << EOF
defaults ssl fetchall nokeep mda "/usr/lib/dovecot/deliver -d %T"                                                
set postmaster <admin@yourdomain>
set bouncemail
set no spambounce
set daemon 300

poll with proto imap port 993 and timeout 120
    user '<user@yourdomain>' with pass "<password>" is '<user>' here

chown vmail:mail /etc/fetchmailrc
chmod 600 /etc/fetchmailrc

cat > /etc/default/fetchmail << EOF
export LC_ALL=C

systemctl restart fetchmail
systemctl enable fetchmail
1 Like

hi i have literaly been looking for this,

if would literaly pay whoem-ever would be willing to add this as a webbased addon to yunohost. where you can configure these accounts in one way or another.

having yunohost running as a personal mail server even running on a residential line would be perfect when you can use fetchmail and smarthost setings to actually send and recieve emails. for example: this would allow you to have a virtuall email inbox of 10gb per inbox even if you webhosting provider only offer mailbox sizes of say 1gb or less. yet for normail mail aplications or even webmail-solutions like nextcloud mail you would have as fast and large mailbox as any professionally priced package would offer.

1 Like