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
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:
-
Install the Sendmail package on your server.
Note
Depending on which operating system distribution you use, you might also need to install the following packages:
sendmail-cf
,m4
, andcyrus-sasl-plain
. -
Verify an identity to use as your From address. For more information, see Creating an email address identity.
If your account is in the Amazon SES sandbox, you must also verify the addresses that you send email to. For more information, see Request production access (Moving out of the Amazon SES sandbox).
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 email traffic over port 25 by default. To avoid timeouts when sending email through the SMTP endpoint from Amazon EC2, you can request that these restrictions be removed. 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, you can modify the procedure in this section to use port 587 rather than port 25.
Configuring Sendmail
Complete the steps in this section to configure Sendmail to send email by using Amazon SES.
Important
The procedure in this section assumes that you want to use Amazon SES in the US West (Oregon) AWS Region. If you want to use a different Region, replace all instances of email-smtp.us-west-2.amazonaws.com in this procedure with the SMTP endpoint of the desired Region. For a list of SMTP endpoint URLs for the AWS Regions where Amazon SES is available, see Amazon Simple Email Service (Amazon SES) in the AWS General Reference.
To configure Sendmail
-
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:
email-smtp.us-west-2.amazonaws.com
"U:root" "I:smtpUsername
" "P:smtpPassword
" "M:PLAIN"In the preceding example, make the following changes:
-
Replace
email-smtp.us-west-2.amazonaws.com
with the Amazon SES SMTP endpoint that you want to use. -
Replace
smtpUsername
with your Amazon SES SMTP user name. -
Replace
smtpPassword
with your Amazon SES SMTP password.
Note
Your SMTP sign-in credentials are different from your AWS Access Key ID and Secret Access Key. For more information about obtaining your SMTP sign-in credentials, see Obtaining Amazon SES SMTP credentials.
When you finish, save
authinfo
. -
-
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'
-
At the command line, type the following command to add support for relaying to the Amazon SES SMTP endpoint.
sudo sh -c 'echo "Connect:
email-smtp.us-west-2.amazonaws.com
RELAY" >> /etc/mail/access'In the preceding command, replace
email-smtp.us-west-2.amazonaws.com
with the address of the Amazon SES SMTP endpoint that you want to use. -
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'
-
At the command line, type the following command to create backups of the
sendmail.cf
andsendmail.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'
-
Add the following lines to the /etc/mail/sendmail.mc file before any
MAILER()
definitions.define(`SMART_HOST', `
email-smtp.us-west-2.amazonaws.com
')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)dnlIn the preceding text, do the following:
-
Replace
email-smtp.us-west-2.amazonaws.com
with the Amazon SES SMTP endpoint that you want to use. -
Replace
example.com
with the domain that you want to use to send email.
When you finish, save the file.
Note
Amazon EC2 restricts communications over port 25 by default. If you're using Sendmail in an Amazon EC2 instance, you should complete the Request to Remove Email Sending Limitations
. -
-
At the command line, type the following command to make sendmail.cf writeable:
sudo chmod 666 /etc/mail/sendmail.cf
-
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
andsendmail-cf
packages are installed on your system. -
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
-
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 su service sendmail restart
-
Complete the following steps to send a test email:
-
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. Replacerecipient@example.com
with the To address. When you finish, press Enter. -
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.
-
-
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.