Configuring Postfix for Sending E-mails Through an External SMTP Server
There are certain cases where you want to set up Postfix to send emails through an external server. One such case is when you are developing a website on your computer and want to test a contact form before uploading to your production server.
Sending e-mails from a dynamic IP is generally a bad idea, since most email providers will automatically flag the message as spam. That leaves us with the option of forwarding the message to a “real” SMTP server.
This tutorial will show you how to set up Postfix to relay emails through an external SMTP server. If you don’t have your own SMTP server, you can alternatively use a SMTP server from a free service, such as Gmail.
The steps below have been tested on Ubuntu.
Install Postfix
Start by installing Postfix and mailutils.
Configure Postfix
Assuming that your external SMTP server listens to SMTP.DOMAIN.TLD:587
, replace the contents of /etc/postfix/main.cf
with:
Create credentials lookup table
Open /etc/postfix/sasl_passwd
and insert your login USERNAME
and PASSWORD
.
Change the file permissions, so that only root has access to it.
Convert the text file to a database file.
Restart Postfix
Finally, restart Postfix for changes to take effect.
That’s it! In case of troubleshooting, don’t forget to check the Postfix log file at /var/log/mail.log
.