Ubuntu HowTo: Postfix SMTP mail server External smtp relay

Original Source Link

How can I configure postfix smtp?

  • External smtp relay
  • Smtp authentication
  • Email send rate limit
  • Schedule emails

If you go to https://help.ubuntu.com and enter “postfix” into the search box, you’ll get a number of helpful articles, including this one https://help.ubuntu.com/community/Postfix to help install and configure postfix.

I’ve installed postfix on PC without static IP address and without buying anything. I’ve used SendGrid’s free plan account and my organization’s microsoft mailbox.

External SMTP Server configuration

  1. Go to sendgrid and register a profile
  2. Go to Sender Authentication and create a new sender (Picture)
    Specify some not-free email (I used office 365 Online account), so Sender could be verified by SendGrid.
  3. Check your mailbox and click Verify Single Sender button in the letter (Picture)
  4. Go to SMTP Relay integration page and create an apikey, you will put in postfix’s sasl_passwd file (Picture). Do not close a verification page till you insert it there and verify.

Postfix configuration:

Install some packages and configure postfix:

sudo apt install postfix mailutils

Configure /etc/postfix/main.cf file the next way, adding or modifying the next lines:

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
append_dot_mydomain = no
compatibility_level = 2
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_security_level=may

smtp_tls_CApath=/etc/ssl/certs
smtp_tls_security_level=encrypt
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = localhost.localdomain

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, localhost
relayhost = [smtp.sendgrid.net]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_tls_security_options = noanonymous

Create /etc/postfix/sasl_passwd file (api secret key would be gained further):

[smtp.sendgrid.net]:587 apikey:SG.kjaksdjkfajskdk_ASDk.lkjaoIO_Kjkoaofs3i99asfd_kkjasdof99882348IKII

Apply settings:

sudo postmap /etc/postfix/sasl_passwd
sudo systemctl restart postfix

Test email sending during SendGrid’s verification

  1. Click Next Verify Integration button. You’ll be on Let’s test your integration page.
  2. Click the Verify Integration button
  3. Run a different terminal window to see logs, using journalctl -f command
  4. Run a command in a terminal to test mail sending, using Single Sender after -r parameter created in External SMTP Server configuration section.

    echo "Test Email message body" | mail -r [email protected] -s "Email test subject" [email protected]
    

As a result, my gmail.com mailbox received a test letter. I’ve also sent it to my yahoo.com account and it also have been received into a Spam folder after a some time of deferring.

Tagged : / / / /

Leave a Reply

Your email address will not be published. Required fields are marked *