/ System Administration

SMTP Relaying Outgoing Mail in Postfix - using Webmin

Configuring your Email Server for incoming/outgoing mails is not a big deal but it causes some serious issues on the other hand. Some popular email services will flag your mails as spam (only if you're lucky - they might completely block them too) as they are not familiar with your host and you might need to contact them to add your address to their whitelist.

Therefore long ago I had decided to use Google Apps for my domain and use Gmail SMTP to support my email service. I have also recently configured Postfix Server to use my Gmail credentials for outgoing mails - a bit tricky to accomplish - so here's a basic tutorial:

Step 1 - Install Required Packages

As you could guess you would need postfix package with mailutils and sendemail to test your settings. So type in:

sudo apt-get install postfix mailutils sendemail

Upon reloading Webmin page you'll see the Postfix Mail Server installed under Servers menu.

Step 2 - Configure Postfix Mail Server

Open Postfix Mail Server module via Webmin and choose the "SMTP Authentication And Encryption" option, then enter the server name and your login credentials:

Go back to the module index and choose "Virtual Domains" and select the "Domain mapping lookup tables" option, then the "..." button:

The following popup will appear, enter the mapping file as:

/etc/postfix/generic

then click Save. Go back to Module Index again and back to Virtual Domains to make sure the settings are processed. Then click the "Add a new mapping" link below. Enter a name and an email address:

You will need to do this for every email address you want to register to use with the SMTP server of yours.

The last step will be to modify the configuration file. So open "Edit Config Files" page from the module index to bring up the "/etc/postfix/main.cf" file and edit it:

  • Add the "smtp_sasl_auth_enable=yes" line BEFORE the "smtp_sasl_password_maps" line.

  • Add the Client TLS Parameters to the end of the file, with a new line character at the end.

Step 3 - Test the Outgoing Emails

Once you restart the service you can now test for the outgoing emails by typing the command below - and modifying it according to your configuration/settings:

sendemail -f sender@example.com -t recipient@example.com -m "Message Body" -u "Message Subject"

You can also attach files by appending the -a parameter and the file name(s):

sendemail -f sender@example.com -t recipient@example.com -m "Message Body" -u "Message Subject" -a file1 file2 file3

Now in addition to taking daily backups of my databases I also email them each night as an attachment so I do not fear losing my data at all.

Koray Alkan

Koray Alkan

Software Developer @Bloomberg. Love classical music, reading and playing the trumpet. Opinions are my own.

Read More