Tag Archives: Mail

Home / Mail
2 Posts

The mailserver of Synology’s DSM is a fine pice. I use it now for some time with BSMTP. There were some minor issues I would like to solve. One of them is modifying some aliases witch can’t be changed with the user interface; postmaster, root and webmaster.

First, make sure there is an account and an alias (assigned to that account) that will be used to deliver the mail. In this example I use admin as an alias and assigned it to an account.

The aliases are stored in a textfile and must be edited. Open an SSH console and open the file with:

vi /var/packages/MailServer/target/etc/aliases

We have to make some modifications in this file. The first thing is to make sure that the root account cannot be mailed. Root NEVER should receive mail! To accomplish this find the following line, remove the # before root and assign the account to be used for root. In this case admin:

# Person who should get root's mail. Don't receive mail as root!
root:        admin

The second modification is adding or changing the alias for the webmaster:

webmaster:   admin
postmaster:  admin

Save the alias file.

Before these modifications will be effective, the new aliases must be stored and Postfix must be made aware of these changes. Type in the SSH console the following commands to achieve this:

/var/packages/MailServer/target/sbin/postfix reload

Other ‘system aliases’ also can be changed with this procedure. Day-to-day aliases can be managed with the user interface of Synology in DSM.

This description assumes you installed the IPKG bootstrap on your NAS. A description in dutch can be found here.

This decribes how an IMAP mailbox can be backed up localy with a Gmail account. However, this method also can be used with all other providers who support IMAP and secure IMAP. Just combine the information from this article and the information of getmail (See bottom of this article.) and your ISP.

The setup

Login to your NAS as root and install getmail with these commands:

ipkg update
ipkg install python
ipkg install py25-getmail

Now that your have the software in place pick a place where the email should be stored. I choose /volume1/Gmail but any folder that is accessible to your ordinary user will do. Still logged in as root issue these commands:

mkdir /volume1/Gmail
cd /volume1/Gmail
mkdir cur new tmp

The last one is necessary for the storage format (Maildir) and getmail doesn’t create these folders itself. Maildir stores each email in a separate file on the disk. If you want another storage format, read the getmail documentation.

You also need a local useraccount. This account will be used by getmail to retrieve the mail and store it locally. By design getmail refuses to use the rootaccount to retrieve. create an accoun and use it in the getmailrc. fill in the name where LOCALUSERNAME is stated in the example below. This user must have the appropiate rights on the /volume1/Gmail folder and the folders below. (chmod -R 700)

Then create a file called /volume1/Gmail/getmailrc with the following content, using your own username and password:

type = SimpleIMAPSSLRetriever
server = imap.gmail.com
mailboxes = ("[Gmail]/All Mail",)
# if you have a German account, use [Google Mail] like this
# mailboxes = ("[Google Mail]/All Mail",)

# From getmail version 4.28 and above you can use: mailboxes=ALL (Case sensitve!)
# This version must be installed manualy. It is not provided in IPKG

username = USERNAME@gmail.com
password = USERPASS

# save each email in a separate file
type = Maildir
path = /volume1/Gmail/

verbose = 2
message_log = /volume1/Gmail/log

# retrieve only new messages
# if set to true it will re-download ALL messages every time!
read_all = false

# do not alter messages
delivered_to = false
received = false

Now everything is in place for getmail to do its work. Do a test run with the following command to test if it will run into any problems.

getmail --getmaildir=/volume1/Gmail

This will start downloading your messages but depending on the size of your email history will take up to a few hours. There is the distinct probability that your ssh connection will time out and drop due to your inactivity. That’s why I ran the first go with nohup so that me logging out wouldn’t stop the process.

nohup getmail -q --getmaildir=/volume1/Gmail & > /volume1/Gmail/nohup.out


Lastly, we obviously want to run getmail periodically and fetch the newest message so open up /etc/crontab with a text editor like vim (you probably need to install it with ipgk first) and add the following line:

0       3       *       *       3       root    /bin/su -c "/opt/bin/getmail -q --getmaildir=/volume1/Gmail"

(It is important so separate the individual parts of the crontab with a tab not a space as otherwise the Synology will delete your entry when you reboot.)

This will run getmail every Wednesday at 3AM when you’re sound asleep. The /bin/su complication is necessary because it appears that the Synology cron can’t run jobs as non-root.

Also, on my Synology you have to restart the cron daemon for it to pick up the changes with a

synoservice --restart crond


To get all the information of GetMail to finetune the getmailrc file, go to their website.

Source: Shizzle