Configure Postfix to use Amazon SES

Install postfix with

apt-get update && apt-get install postfix libsasl2-modules -y

Update postfix config with

sed -i "s/default_transport = error/# default_transport = error/g" /etc/postfix/
sed -i "s/relay_transport = error/# relay_transport = error/g" /etc/postfix/
sed -i "s/relayhost =/# relayhost =/g" /etc/postfix/


vi /etc/postfix/

Add to end of the file

relayhost = [SMTP_SERVER_NAME]:587
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

In the above, replace SMTP_SERVER_NAME with your Amazon SES mail server, for example “”, you can see it in your Amazon SES console.


echo "[SMTP_SERVER_NAME]:587 SMTP_USERNAME:SMTP_PASSWORD" > /etc/postfix/sasl_passwd

Replace SMTP_SERVER_NAME, SMTP_USERNAME and SMTP_PASSWORD with your actual credentials.

Now run

postmap /etc/postfix/sasl_passwd

Restart postfix

service postfix restart

You can test mail working with

echo "test" | mail -r you@SES_VERIFIED_DOMAIN -s "test" [email protected]

For sending from Apache, you may need to set myorigin in postfix confgiration with your veirfied domain. This can be done by editing

vi /etc/mailname

You can verify myorgin with

root@ip-172-31-30-228:~# postconf | grep myorigin
append_at_myorigin = yes
myorigin = /etc/mailname

Sending Mail from Amazon EC2

When sending email from Amazon EC2, it rejected with

Aug 28 17:20:59 ip-172-31-11-238 postfix/smtp[27260]: 1BB10831A0: to=,[]:587, delay=2.9, delays=0.02/0.03/1.7/1.2, dsn=5.0.0, status=bounced (host[] said: 554 Message rejected: Email address is not verified. The following identities failed the check in region US-EAST-1: [email protected] (in reply to end of DATA command))

Problem is solved by editing

vi /etc/postfix/


myhostname = ip-172-31-28-58.ap-southeast-2.compute.internal

Replace with


Amazon SES

Need help with Linux Server or WordPress? We can help!

Leave a Reply

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