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.
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 a Sendmail build that supports STARTTLS. Depending on your operating system, you might also need the
sendmail-cf,m4, andcyrus-sasl-plainpackages. -
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 outbound email traffic over port
25by default. This procedure uses port25. 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.
Replace smtp_endpoint with the endpoint from your SMTP
credentials.
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:smtp_endpoint"U:root" "I:smtpUsername" "P:smtpPassword" "M:PLAIN"In the preceding example, make the following changes:
-
Replace
smtp_endpointwith the endpoint from your SMTP credentials. -
Replace
smtpUsernamewith the user name from your SMTP credentials. -
Replace
smtpPasswordwith the password from your SMTP credentials.
When you finish, save
authinfo. -
-
At the command line, enter the following command to generate the
/etc/mail/authinfo.dbfile:sudo sh -c 'makemap hash /etc/mail/authinfo.db < /etc/mail/authinfo' -
At the command line, type the following command to allow relaying to the selected SMTP endpoint.
sudo sh -c 'echo "Connect:smtp_endpointRELAY" >> /etc/mail/access'In the preceding command, replace
smtp_endpointwith the endpoint from your SMTP credentials. -
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.cfandsendmail.mcfiles: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', `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)dnlIn the preceding text, do the following:
-
Replace
smtp_endpointwith the endpoint from your SMTP credentials. -
Replace
example.comwith the domain that you want to use to send email.
When you finish, save the file.
-
-
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'NoteIf you encounter errors such as "Command not found" and "No such file or directory," make sure that the
m4andsendmail-cfpackages 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 restartDepending on the version of Linux or Sendmail, if the above doesn't work, try the following:
sudo service sendmail restart -
Complete the following steps to send a test email:
-
At the command line, enter the following command.
/usr/sbin/sendmail -vfsender@example.comrecipient@example.comReplace
sender@example.comwith your From email address. Replacerecipient@example.comwith the To address. When you finish, press Enter. -
Enter the following message content. Press Enter at the end of each line.
From:sender@example.comTo:recipient@example.comSubject: 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.