note: Amazon Simple Email Service (SES) 簡單設定心得

2013073010:39


https://console.aws.amazon.com/ses/home#smtp-settings:

畫面有說明
使用 Amazon SES SMTP 前
需先建立 SMTP credentials 
就是新增一組 SMTP 專用的帳號/密碼

IAM User Name 自動產生,可自定 (這個名稱 非 SMTP 用的帳號)


產生後的 SMTP Username / Password
資料要自己記下來
忘記了,就只能刪掉這組 User 資料、重新產生一組新帳號


帳號就列表在 IAM
https://console.aws.amazon.com/iam/home#users


PHPMailer 的範例

<?php

 require_once('PHPMailer/class.phpmailer.php');
    $to         = "[email protected]";
    $from       = "[email protected]";
    $subject    = "a test subject";
    $body       = "email body content goes here";

    $mail       = new PHPMailer();
    $mail->IsSMTP(true);            // use SMTP

    $mail->SMTPDebug  = 1;        // enables SMTP debug information (for testing)
                                    // 1 = errors and messages
                                    // 2 = messages only
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->Host       = "tls://email-smtp.us-east-1.amazonaws.com"; // Amazon SES server, note "tls://" protocol
    $mail->Port       = 465;                    // set the SMTP port
    $mail->Username   = "AKIAIXUP2DRZJ55XXXXX";  // SES SMTP  username
    $mail->Password   = "ApBTvPMad4nvhjd+zDf1123123123123123123";  // SES SMTP password

    $mail->SetFrom($from, 'First Last');
    $mail->AddReplyTo($from,'First Last');
    $mail->Subject    = $subject;
    $mail->MsgHTML($body);
    $address = $to;
    $mail->AddAddress($address, $to);

    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
      echo "Message sent!";
    }

    
/*
PHP 要支援 OpenSSL 
不然會有錯誤訊息
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "tls" - 
did you forget to enable it when you configured PHP? (11468)SMTP Connect() failed.
*/



SES Dashboard 會顯示目前的使用狀況
以及每日可發信的數量、每秒最大可發幾封信
https://console.aws.amazon.com/ses/home#dashboard:



Deliveries
發信數量

Bounces
被退信的數量

Complaints
發出的信,若有人按了「垃圾信」
SES 會以 [email protected] 身份發信通知你(寄到你 FROM信箱中)
Complaints 數字就會增加

Rejects



用滿 Quota 後
就卡住,會得到這個訊息:

 Mailer Error: SMTP Error: Data not accepted.<p>SMTP server error: Throttling failure: Daily message quota exceeded.</p>

要等多久才能繼續發信呢?

這頁有說: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/increase-sending-limits.html

Send near your current quota—If your volume stays close to your quota without exceeding it, Amazon SES can detect this usage pattern and automatically increase your quota.


原來: Sending Quota: send 10000 emails per 24 hour period

指的是 最近 24小時內 只能發送 10000 封信

例如:
現在這 1 小時連續發了 10000 封信後
接下來的 23 小時都將不能發信

舉例:

00時 發 5000封
01時 發 5000封  (已用滿 Quota)
02時 不能發信
: :
24時 不能發信
00時 可以再發 5000封 (SES Dashboard 畫面會顯示:  5000 Sent    5000 Remaining
01時 可以再發另外 5000封


--

另外 在 SES Dashboard 中
EMail Address、Domains 這兩項也要做一下身份驗證
其中 Domains 部份要配合修改 DNS 資料


當做了 DKIM 相關驗證後
發出去的信件
可以看到 Header 中有這段:

Received-SPF: pass (google.com: domain of 00000140351da2da-260e8a4f-ed03-4a2d-af1a-9ae7c7629955-000000@amazonses.com 
    designates 54.240.9.13 as permitted sender) client-ip=54.240.9.13;
Authentication-Results: mx.google.com;
       spf=pass (google.com: domain of 00000140351da2da-260e8a4f-ed03-4a2d-af1a-9ae7c7629955-000000@amazonses.com 
    designates 54.240.9.13 as permitted sender) 
    smtp.mail=00000140351da2da-260e8a4f-ed03-4a2d-af1a-9ae7c7629955-000000@amazonses.com

不然就會看到類似這樣:
Received-SPF: neutral (google.com: 220.135.68.xxx is neither permitted nor denied by best guess record for domain of 
           [email protected]) client-ip=220.135.68.xxx;
Authentication-Results: mx.google.com;
       spf=neutral (google.com: 220.135.68.xxx is neither permitted nor denied by best guess record for domain of 
       [email protected]) [email protected]


**




參考資料:

Amazon Simple Email Service (Amazon SES) 簡介

使用Amazon SES批量发送邮件

Amazon SES介紹 - SES發送郵件的過程

如何正確發送(大量) Email 信件

使用 DKIM 驗證電子郵件 - Google Apps說明
 



  •    (悄悄話) 1F
  • <悄悄話留言,不公開>