顯示具有 ses 標籤的文章。 顯示所有文章
顯示具有 ses 標籤的文章。 顯示所有文章

2016年6月8日 星期三

使用 Azure 寄信方案 - SendGrid: Marketing & Transactional Email Service

SendGridDashboard

上週出了個大包,原先採用 AWS SES 寄信時,因為綜合原因導致 bounce rate 上升,接著就被停權使用 AWS SES 服務了!這件事說小事也可以,說嚴重很嚴重,單就看你的服務營運跟面對的心態。我把它當很嚴重的事來處理 Orz 包含盡可能跟 AWS 業務互動,再來沒打通 AWS SES 服務前,就趕緊找找替代方案了!

除了用自家的 mail server 寄信撐外,就來找找其他家服務了,於是乎 Azure 就出現了、SendGrid 也出現了!

使用 SendGrid 真的還滿方便的,除了可以查詢寄了哪些信外,什麼都沒做還能提供使用者開信紀錄!真是太便利了。

只是談錢就傷感情了 XD
使用 Sendgrid 一個月發送 40k 封信,要價 9.95 歐元;假設一個月送 40k 封信,若每封 500kb,採用 AWS SES 則是 20GB 流量/month + 1333 封信/day ,總價不到3美金。

2015年3月11日 星期三

AWS 筆記 - 使用 Amazon Simple Email Service (Amazon SES) 服務


原先在開發電子報服務時就有要用,嘗試到一半就被其他事件 Orz 所以還是花點時間筆記一下這塊。首先,使用上需要 Amazon 帳號,打通後則是要用 AWS SES 服務的流程而已,其中 AWS 許多流程仍是依據 IAM 權限管理的,其實也是個挺漂亮的架構,粗略流程:
  1. 透過 AWS 最高權限,在 Amazon SES -> SMTP Settings -> Create My SMTP Credentials,將得到一組 SMTP Username 和 Password 可使用。過程中會建立一個 AWS user,我印象中早期是要自己去處理的
  2. 預設是 sandbox 環境,只能寄給已驗證的收信者,在 Amzaon SES Verified Sender 可以新增幾個試試。
  3. 透過 SMTP protocol 寄信看看
此次使用 PHPMailer 來測試:

$ git clone https://github.com/Synchro/PHPMailer.git
$ vim PHPMailer/AWS-SES-test.php
<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'email-smtp.us-west-2.amazonaws.com';
$mail->SMTPAuth = true;
$mail->Username = 'YourSMTPUsername';
$mail->Password = 'YourSMTPPassword';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

$mail->From = 'YourSenderEmail';
$mail->FromName = 'Mailer';

$mail->addAddress('YourTargetEmail');

$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

$ php PHPMailer/AWS-SES-test.php


在 sandbox 中,如果 $mail->addAddress 或是 $mail->From 使用的不是驗證過的,會出現 554 Message rejected: Email address is not verified.


最後,測試都差不多了,想要正式使用時,在申請一下  Requesting Production Access to Amazon SES 即可。理由可以很簡單,例如寄信給註冊的使用者們,不到20個英文字就搞定啦,但各個 region 必須分開申請。