Skip to content

Instantly share code, notes, and snippets.

@beardedtim
Last active February 24, 2020 15:19
Show Gist options
  • Save beardedtim/79e0b9da72febf8fec84c27cebb3f722 to your computer and use it in GitHub Desktop.
Save beardedtim/79e0b9da72febf8fec84c27cebb3f722 to your computer and use it in GitHub Desktop.
Integrating SES with Postfix

Overview

We have failing SMTP requests because our port 25 was closed on our EC2 instances. These are the steps that you might want to follow in order to fix the SMTP issues and to be able to send email again.

Prior Art

You can look here for the docs that I followed to figure out the path forward.

Steps

  1. SSH into the lightsail instance
  2. Create a new file so that you can easily change text/spacing/etc
    • The file content:
    #!/bin/bash
    
    sudo postconf -e "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_security_level = encrypt" \
    "smtp_tls_note_starttls_offer = yes"
  3. Edit the password: sudo vim /etc/postfix/sasl_passwd
    • Should look like this [email-smtp.us-east-1.amazonaws.com]:587 SMTPUSERNAME:SMTPPASSWORD
    • Create a new SMTP user on AWS or ask @Tim for the root
  4. Hashmap the new creds sudo postmap hash:/etc/postfix/sasl_passwd
  5. Change ownership and permissions
    • 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
  6. Restart postfix: sudo service postfix restart
  7. Send a test email:
    • You will enter the following line by line, pressing enter or carriage return after each
    • Be sure to replace [email protected] with whatever email you want to send the test to
    sendmail -f [email protected] [email protected]
    From: Sender Name [email protected]
    Reply-To: [email protected]
    Subject: Amazon SES test mail
    test mail form ses.
    .
    
    • Note: the last . is important. It tells the computer that you are done
    • NOTE: You might have to do "Sender Name" <[email protected]> in the From: header. Try without and if that gives you 5xx errors in the log about Sender@ip and Name@ip not working, you will need to try the different format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment