Configure Postfix to Relay to Amazon SES SMTP Server

Tags: April 27, 2016 6:55 AM

Goal

Configure internal Postfix installation to relay email to Amazon SES SMTP server.

Steps

Make sure you have done everything that Amazon SES requires you before you're able to send email using Amazon SES. After that you can start to proceed steps below.

1. Install Postfix

$ sudo apt-get install postfix libsasl2-modules

2. Configure SMTP Credential

Make sure you already have Amazon SES username and secret key. Now we need to add the credential into postfix lookup table.
$ sudo cat > /etc/postfix/sasl_passwd
[email-smtp.us-east-1.amazonaws.com]:587 YOUR_USERNAME:YOUR_SECRET_KEY
$ sudo chmod 0600 /etc/postfix/sasl_passwd
You may change the smtp server email-smtp.us-east-1.amazonaws.com according region where you setup the Amazon SES. Now update the postfix lookup table.
$ sudo postmap /etc/postfix/sasl_passwd

3. Edit /etc/postfix/main.cnf

Put the following lines to the /etc/postfix/main.cnf.
relayhost = [email-smtp.us-east-1.amazonaws.com]:587

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
Then restart postfix.
$ sudo service postfix restart

4. Test the Configuration

Try to sending an email to some address. We will use telnet command to send the email.
$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 97e02a815796 ESMTP Postfix (Ubuntu)
HELO localhost              
250 97e02a815796
MAIL FROM: no-reply@example.com
250 2.1.0 Ok
RCPT TO: me@rioastamal.net
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: Testing Amazon SES Relay
From: no-reply@example.com

This should be arrive in your inbox :)
.
250 2.0.0 Ok: queued as 8093B90
^]
telnet> quit
Make sure that no-reply@example.com is verified and permitted to send email on your Amazon SES dashboard console.

References

Share on Facebook Twitter

0 comments:

Post a Comment