opensslコマンドでAWS SESを経由でメール送信テスト


AWSのSimple Email Service(SES)ではUse Transport Layer Security (TLS)を使わないいけないので、簡単にtelnetから接続できません。
下記はサーバーから送信できるかどうかを試してみる手順です。

SMTP credentialsトークンの生成

$ perl -MMIME::Base64 -e 'print encode_base64("auth-user-name");'
QUtJ...auth-user....RMSUE=
$ perl -MMIME::Base64 -e 'print encode_base64("auth-password");'
QXVDR...auth-pass....3Q= 

メール送信

$ openssl s_client -crlf -quiet -starttls smtp -connect email-smtp.us-west-2.amazonaws.com:587
depth=2 C = US, O = "VeriSign, Inc.", OU = VeriSign Trust Network, OU = "(c) 2006 VeriSign, Inc. - For authorized use only", CN = VeriSign Class 3 Public Primary Certification Authority - G5
verify return:1
depth=1 C = US, O = Symantec Corporation, OU = Symantec Trust Network, CN = Symantec Class 3 Secure Server CA - G4
verify return:1
depth=0 C = US, ST = Washington, L = Seattle, O = "Amazon.com, Inc.", CN = email-smtp.us-west-2.amazonaws.com
verify return:1
250 Ok
EHLO smtp.example.com                              # ← 入力
250-email-smtp.amazonaws.com
250-8BITMIME
250-SIZE 10485760
250-STARTTLS
250-AUTH PLAIN LOGIN
250 Ok
AUTH LOGIN                                        # ← 入力
334 VXNlcm5hbWU6
QUtJ...auth-user....RMSUE=                        # ← 入力
334 UGFzc3dvcmQ6
QXVDR...auth-pass....3Q=                          # ← 入力
235 Authentication successful.
MAIL FROM: [email protected]                       # ← 入力
250 Ok
rcpt TO: [email protected]                         # ← 入力
250 Ok
DATA                                              # ← 入力
354 End data with <CR><LF>.<CR><LF>
From: [email protected]                            # ← 入力
Subject: SES TEST                                 # ← 入力
Hello World                                       # ← 入力
.                                                 # ← 入力
250 Ok 0101015af9158693-aec4e9fe-5e1f-4211-826a-f9ca21411aac-000000
421 Timeout waiting for data from client.         # 入力せずにtimeout

メール確認

Delivered-To: [email protected]
Received: by .........;
        Wed, 22 Mar 2017 19:53:43 -0700 (PDT)
X-Received: by .......
....
From: [email protected] 
Subject: SES TEST
Message-ID: <0101015af9158693-aec4e9fe-5e1f-4211-826a-f9ca21411aac-000000@us-west-2.amazonses.com>
Date: Thu, 23 Mar 2017 02:53:42 +0000
X-SES-Outgoing: 2017.03.23-54.240.27.29
Feedback-ID: 1.us-west-2.jj20/+c1csFRX4yd6JTZjvVI/J8oJxtSw+150dH6qcs=:AmazonSES

Hello World

参考