Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Postfix With External SMTP Server

DZone 's Guide to

Postfix With External SMTP Server

Learn more about sending email via Postfix with an external SMTP server.

· Open Source Zone ·
Free Resource

postfix smtp server

Postfix SMTP server


Introduction 

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. pepipostsendgrid, Amazon SES, and many more, to send their emails.

Advantages of ESP

  1. You don't need to worry about email deliverability. Instead, you just need to keep your postfix up and relaying mails to ESP.
  2. Most important ESP helps you to avoid your email getting tagged as spam. You can hamper your IP reputation.
  3. You can check out ways to avoid having your emails sent to the spam folder.

Requirements

  • A fully qualified domain (your brand.com)
  • An SMTP username and password from your emails service provider
  • Postfix installed with all dependencies solved

Installation

  1. Ubuntu  ---  sudo apt-get install postfix 
  2. centos    ---  sudo yum install postfix   
  3. fedora    ---  sudo dnf install postfix  

Configuration

  1. Check for postfix status  --- systemctl status postfix  (Ensure it is stopped)
  2. Open and make changes in the main.cf file   --  vim /etc/postfix/main.cf  
  3. Update hostname with your fully qualified domain --  myhostname = m3.example.com 
  4. Open s asl_passed file in postfix --  vim /etc/postfix/sasl_passwd  
  5. Add the lines accordingly, as per the details provided by your ESP -- [smtp.example.com]  myusername:myp@ssw0rd 

    Note: When using TLS, add the port with the host  [smtp.example.com]:587  myusername:myp@ssw0rd
  6. Updating hash file sasl_passwd.db by postmapping the file  sudo postmap hash:/etc/postfix/sasl_passwd 
  7. Set the ownership and permission for the sasl_passwd.db  file
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 ---  vim /etc/postfix/main.cf

 8. Configure the custom setting at the end of the file-- vim /etc/postfix/main.cf

# 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

Done!! 

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.

Further Reading

Setting Up Postfix Locally to Send Email Via Google SMTP

Beginner's Guide to Configuring an Email Service Task With a Process Automation Manager

Linux Mail Server: Installation + Configuration + Security + Tweaks

Topics:
postfix ,emails of architects ,ubuntu ,centos ,fedora ,smtp

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}