Configure Postfix to use Amazon SES
Install postfix with
1 |
apt-get update && apt-get install postfix libsasl2-modules -y |
Update postfix config with
1 2 3 |
sed -i "s/default_transport = error/# default_transport = error/g" /etc/postfix/main.cf sed -i "s/relay_transport = error/# relay_transport = error/g" /etc/postfix/main.cf sed -i "s/relayhost =/# relayhost =/g" /etc/postfix/main.cf |
Edit
1 |
vi /etc/postfix/main.cf |
Add to end of the file
1 2 3 4 5 |
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 “email-smtp.us-east-1.amazonaws.com”, you can see it in your Amazon SES console.
Run
1 |
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
1 |
postmap /etc/postfix/sasl_passwd |
Restart postfix
1 |
service postfix restart |
You can test mail working with
1 |
echo "test" | mail -r you@SES_VERIFIED_DOMAIN -s "test" admin@serverok.in |
For sending from Apache, you may need to set myorigin in postfix confgiration with your veirfied domain. This can be done by editing
1 |
vi /etc/mailname |
You can verify myorgin with
1 2 3 4 |
root@ip-172-31-30-228:~# postconf | grep myorigin append_at_myorigin = yes myorigin = /etc/mailname root@ip-172-31-30-228:~# |
Sending Mail from Amazon EC2
When sending email from Amazon EC2, it rejected with
1 |
Aug 28 17:20:59 ip-172-31-11-238 postfix/smtp[27260]: 1BB10831A0: to=<admin@serverok.in>, relay=email-smtp.us-east-1.amazonaws.com[23.23.196.20]:587, delay=2.9, delays=0.02/0.03/1.7/1.2, dsn=5.0.0, status=bounced (host email-smtp.us-east-1.amazonaws.com[23.23.196.20] said: 554 Message rejected: Email address is not verified. The following identities failed the check in region US-EAST-1: ozmask@ip-172-31-28-58.ap-southeast-2.compute.internal (in reply to end of DATA command)) |
Problem is solved by editing
1 |
vi /etc/postfix/main.cf |
Find
1 |
myhostname = ip-172-31-28-58.ap-southeast-2.compute.internal |
Replace with
1 |
myhostname = AWS_VERIFIED_DOMAIN_HERE |