Menu
Amazon Simple Email Service
Developer Guide (API Version 2010-12-01)

Using the Command Line to Send Email Through the Amazon SES SMTP Interface

You can use a command line utility to interact directly with the Amazon SES SMTP interface. The command line interface can be helpful for testing purposes or for writing software that must communicate directly using the SMTP protocol.

To protect our customers, all communication with the SMTP interface must take place using TLS (Transport Layer Security). For SMTP command line usage, we recommend that you use OpenSSL. OpenSSL, which is available at https://www.openssl.org, includes a command line utility for communicating over a TLS-secured connection.

Example : Using OpenSSL to Send Email Using Amazon SES

This example shows how to connect to the Amazon SES SMTP endpoint in the US West (Oregon) region and use standard SMTP commands to send an email message. Some of the output in the example is omitted for brevity.

Using TLS Wrapper:

Copy
openssl s_client -crlf -quiet -connect email-smtp.us-west-2.amazonaws.com:465
  • s_client—Specifies that this connection will use TLS (SSL).

  • -crlf—Translates line feed characters (LF) to CR+LF (carriage return and line feed).

  • -quiet—Inhibits printing of session and certificate information. This implicitly turns on -ign_eof as well.

  • -connect—Specifies the SMTP host and port.

Using STARTTLS:

Copy
openssl s_client -crlf -quiet -starttls smtp -connect email-smtp.us-west-2.amazonaws.com:25
  • s_client—Specifies that this connection will use TLS (SSL).

  • -crlf—Translates line feed characters (LF) to CR+LF (carriage return and line feed).

  • -quiet—Inhibits printing of session and certificate information. This implicitly turns on -ign_eof as well.

  • -starttls smtp—Specifies STARTTLS negotiation.

  • -connect—specifies the SMTP host and port.

After you make the connection using one of the preceding commands, the Amazon SES SMTP interface identifies itself by presenting its server certificate.

Copy
CONNECTED(00000003) ... <output omitted> Server certificate -----BEGIN CERTIFICATE----- MIID2jCCAue4gAwIBAgIAMEkqjWRxm3cqMA0tGC2GxSI37DQEBQ6UAMIGHjswCQD VQQEwVUzErTMBEGaxA51UECBfMKV2Fza7GluZ3RvbjEMxA4GAUEByEXAMPLECERT ... <output omitted> --- 220 localhost ESMTP SES 2010-12-03

At this point, use the EHLO command to identify your client. Specify the hostname of the system from which you are logging in.

Copy
EHLO bob-desktop.example.com 250-localhost ... <output omitted> 250-AUTH LOGIN 250 Ok

You can now use the AUTH LOGIN command to supply your SMTP credentials. You must base64-encode your SMTP username and password. The server prompts ("Username:" and "Password:") are similarly encoded, and appear with the SMTP response code 334.

Note

To base64-encode a string in Linux, you can use the following command (replace "SMTP-USERNAME" with your SMTP username): echo -n "SMTP-USERNAME" | base64

For example, if your SMTP username credential is c2VzLXNtdHAtdXNlcEXAMPLE and your password is SkFYTVpaM3k0U2paVEYwOFpLEXAMPLE, you would supply your base64-encoded credentials as follows:

Copy
AUTH LOGIN 334 VXNlcm5hbWU6 YzJWekxYTnRkSEF0ZFhObGNFWEFNUExF 334 UGFzc3dvcmQ6 U2tGWVRWcGFNM2swVTJwYVZFWXdPRnBMRVhBTVBMRQ== 235 Authentication successful.

Specify the sender and recipient by using the MAIL FROM and RCPT TO commands. For MAIL FROM, you must use an email address that you have already verified with Amazon SES. For more information about verification, see Verifying Email Addresses and Domains in Amazon SES.

Copy
MAIL FROM:bob@example.com 250 Ok RCPT TO:alice@example.com 250 Ok

Issue the DATA command to specify the email headers and the body of the message. The headers and the body must be separated by at least one blank line. In this example, only the Subject: header is being used. A dot (".") on a line by itself signifies the end of the message body.

Copy
DATA 354 End data with <CR><LF>.<CR><LF> Subject:Hello from Amazon SES! This email was sent using the Amazon SES SMTP interface. . 250 Ok

Now that the message has been sent, use the QUIT command to close the SMTP connection.

Copy
QUIT 221 Bye closed

Note

For more information about SMTP, go to https://tools.ietf.org/html/rfc5321.