Postfix With External SMTP Server
Learn more about sending email via Postfix with an external SMTP server.
Join the DZone community and get the full member experience.Join For Free
Postfix, being an open-source MTA (mail transfer agent), has gained a lot of attention after Sendmail. The functionality of both is the same — they are used to route and deliver emails.
You may also like: Setting Up Postfix Locally to Send Email Via Google SMTP
But, there are many reasons developers don't like to send mail using the local server where postfix is installed. Instead, they prefer to opt for an ESP (email service provider), i.e. pepipost, sendgrid, Amazon SES, and many more, to send their emails.
Advantages of ESP
- You don't need to worry about email deliverability. Instead, you just need to keep your postfix up and relaying mails to ESP.
- Most important ESP helps you to avoid your email getting tagged as spam. You can hamper your IP reputation.
- You can check out ways to avoid having your emails sent to the spam folder.
- A fully qualified domain (your brand.com)
- An SMTP username and password from your emails service provider
- Postfix installed with all dependencies solved
- Ubuntu ---
sudo apt-get install postfix
- centos ---
sudo yum install postfix
- fedora ---
sudo dnf install postfix
- Check for postfix status ---
systemctl status postfix(Ensure it is stopped)
- Open and make changes in the main.cf file --
- Update hostname with your fully qualified domain --
myhostname = m3.example.com
- Open s
asl_passedfile in postfix --
- Add the lines accordingly, as per the details provided by your ESP --
Note: When using TLS, add the port with the host
- Updating hash file sasl_passwd.db by postmapping the file
sudo postmap hash:/etc/postfix/sasl_passwd
- Set the ownership and permission for the
sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
Once you have done this with the ownership of the file, you can set the relay host.
Configure your relay host in main.cf file by updating the relay host ---
8. Configure the custom setting at the end of the file--
# enable SASL authentication smtp_sasl_auth_enable = yes # disallow methods that allow anonymous authentication. smtp_sasl_security_options = noanonymous # where to find sasl_passwd smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd # Enable STARTTLS encryption smtp_use_tls = yes # where to find CA certificates smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
9. Restart your postfix --
sudo service postfix restart
If you are stuck, check the details in this post of mine. Please let me know if you found this post helpful in the comments.
Published at DZone with permission of vikram sahu. See the original article here.
Opinions expressed by DZone contributors are their own.