Howto send mail from Synology NAS Commandline using Google Mail Relay

If you tried to send mails from your NAS having your gmail account as sender address, you might ended up in searching your mails in the SPAM folder. This is because the mail is not sent using the google SMTP server. However you can fix that by following the next steps:

  1. In DSM, install the package “E-Mail Server”
  2. Run the “E-Mail Server” app to start the configuration
  3. Click on “SMTP” and tick the “Enable SMTP” checkbox
  4. Tick the “Authorization required for mail clients except Mail Station” if you only want to send mails from the NAS itself.
  5. Click on SMTP relay
  6. Tick “Enable SMTP Relay”
  7. Server is:
  8. Port is: 587
  9. Choose “Always use a secure connection (TLS)”
  10. Tick “Authentication Required” and enter your gmail account and password. Don’t forget to add the “” behind your gmail account.
  11. Click OK twice (first on relay setup, then on e-mail server setup)

Now your done. Login to your NAS using your favorite SSH client and try to send a mail:

DiskStation> sendmail -F “Synology Station” -f “” -t << EOF
Subject: Synology Mail Test
Seems to work. Hooray.

Check your gmail inbox and there you are. You can now use this command in your scripts.


4 thoughts on “Howto send mail from Synology NAS Commandline using Google Mail Relay

  1. Thanks for the thoroughly detailed set of steps. My DiskStation’s system time keeps drifting and messing up my 2-factor auth until I force a time sync (forum thread). I was looking for a way to notify myself when sync’ing the time using the Task Scheduler and your solution was the best I found. Thanks for sharing!

    Have a nice day šŸ™‚

  2. Hi, this was really helpful.

    I’m trying to use sendmail for synagios and it seems they require sendmail command in one continuously command line instead of using EOF. Is that possible using sendmail?

    • Hi Calvin

      How does the error message look like if you reproduce the example command in my posting? The ” << EOF" is a feature that is given by the shell and not by sendmail. If possible / available, start "bash" first and retry the command and see what happens.


      • Thanks for getting back to me, I actually figured out the solution instead of using EOF and just piping the message in with printf as follows:

        /usr/bin/printf “Subject: ** email subject**\n\n email body message…” | /usr/sbin/sendmail -F “Sendmail” -f “” -t

        I thought there was something wrong with sendmail, but I’m actually having another problem configuring Nagios, which probably would be out of the scope of assistance here. Thanks again!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s