Integrating Amazon SES with Sendmail - Amazon Simple Email Service
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

Integrating Amazon SES with Sendmail

Sendmail was released in the early 1980s, and has been continuously improved ever since. It's a flexible and configurable message transfer agent (MTA) with a large community of users. Sendmail was acquired by Proofpoint in 2013, but Proofpoint continues to offer an open source version of Sendmail. You can download the open source version of Sendmail from the Proofpoint website, or through the package managers of most Linux distributions.

The procedure in this section shows you how to configure Sendmail to send email through Amazon SES. This procedure was tested on a server running Ubuntu 18.04.2 LTS.

Note

Sendmail is a third-party application, and isn't developed or supported by Amazon Web Services. The procedures in this section are provided for informational purposes only, and are subject to change without notice.

Prerequisites

Before you complete the procedure in this section, you should complete the following steps:

If you're using Amazon SES to send email from an Amazon EC2 instance, you should also complete the following steps:

  • You may need to assign an Elastic IP Address to your Amazon EC2 instance in order for receiving email providers to accept your email. For more information, see Amazon EC2 Elastic IP addresses in the Amazon EC2 User Guide.

  • Amazon Elastic Compute Cloud (Amazon EC2) restricts outbound email traffic over port 25 by default. This procedure uses port 25. Request removal of the restriction before using this procedure from Amazon EC2. For more information, see How do I remove the restriction on port 25 from my Amazon EC2 instance or AWS Lambda function? in the AWS Knowledge Center. Alternatively, change the procedure to use port 587.

Configuring Sendmail

Complete the steps in this section to configure Sendmail to send email by using Amazon SES.

Note

Replace smtp_endpoint with the endpoint from your SMTP credentials.

To configure Sendmail
  1. In a file editor, open the file /etc/mail/authinfo. If the file doesn't exist, create it.

    Add the following line to /etc/mail/authinfo:

    AuthInfo:smtp_endpoint "U:root" "I:smtpUsername" "P:smtpPassword" "M:PLAIN"

    In the preceding example, make the following changes:

    • Replace smtp_endpoint with the endpoint from your SMTP credentials.

    • Replace smtpUsername with the user name from your SMTP credentials.

    • Replace smtpPassword with the password from your SMTP credentials.

    When you finish, save authinfo.

  2. At the command line, enter the following command to generate the /etc/mail/authinfo.db file:

    sudo sh -c 'makemap hash /etc/mail/authinfo.db < /etc/mail/authinfo'
  3. At the command line, type the following command to allow relaying to the selected SMTP endpoint.

    sudo sh -c 'echo "Connect:smtp_endpoint RELAY" >> /etc/mail/access'

    In the preceding command, replace smtp_endpoint with the endpoint from your SMTP credentials.

  4. At the command line, type the following command to regenerate /etc/mail/access.db:

    sudo sh -c 'makemap hash /etc/mail/access.db < /etc/mail/access'
  5. At the command line, type the following command to create backups of the sendmail.cf and sendmail.mc files:

    sudo sh -c 'cp /etc/mail/sendmail.cf /etc/mail/sendmail_cf.backup && cp /etc/mail/sendmail.mc /etc/mail/sendmail_mc.backup'
  6. Add the following lines to the /etc/mail/sendmail.mc file before any MAILER() definitions.

    define(`SMART_HOST', `smtp_endpoint')dnl define(`RELAY_MAILER_ARGS', `TCP $h 25')dnl define(`confAUTH_MECHANISMS', `LOGIN PLAIN')dnl FEATURE(`authinfo', `hash -o /etc/mail/authinfo.db')dnl MASQUERADE_AS(`example.com')dnl FEATURE(masquerade_envelope)dnl FEATURE(masquerade_entire_domain)dnl

    In the preceding text, do the following:

    • Replace smtp_endpoint with the endpoint from your SMTP credentials.

    • Replace example.com with the domain that you want to use to send email.

    When you finish, save the file.

  7. At the command line, type the following command to make sendmail.cf writeable:

    sudo chmod 666 /etc/mail/sendmail.cf
  8. At the command line, type the following command to regenerate sendmail.cf:

    sudo sh -c 'm4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf'
    Note

    If you encounter errors such as "Command not found" and "No such file or directory," make sure that the m4 and sendmail-cf packages are installed on your system.

  9. At the command line, type the following command to reset the permissions of sendmail.cf to read only:

    sudo chmod 644 /etc/mail/sendmail.cf
  10. At the command line, type the following command to restart Sendmail:

    sudo /etc/init.d/sendmail restart

    Depending on the version of Linux or Sendmail, if the above doesn't work, try the following:

    sudo service sendmail restart
  11. Complete the following steps to send a test email:

    1. At the command line, enter the following command.

      /usr/sbin/sendmail -vf sender@example.com recipient@example.com

      Replace sender@example.com with your From email address. Replace recipient@example.com with the To address. When you finish, press Enter.

    2. Enter the following message content. Press Enter at the end of each line.

      From: sender@example.com To: recipient@example.com Subject: Amazon SES test email This is a test message sent from Amazon SES using Sendmail.

      When you finish entering the content of the email, press Ctrl+D to send it.

  12. Check the recipient email's client for the email. If you can't find the email, check the junk mail folder. If you still can't find the email, check the Sendmail log on your mail server. The log is often located at /var/log/mail.log or /var/log/maillog.