[AWS SES] 教你 AWS SES 如何設定自訂驗證信件


情境:

我的專案有代發信件的功能,為了能夠實現代理發送,在本機裝了postfix,但信件經常被丟到垃圾信,不然就是客戶收信速度太慢,於是剛好看到AWS SES也能夠實現代理發送,只不過要先發送SES驗證信件到客戶端,驗證完才能夠由SES實現代理發送,這篇來記錄下如何設定自訂驗證信件。

步驟:

  1. 首先必須先裝好AWS CLI,因為目前AWS 編輯自訂驗證信件只能透過AWS CLI,安裝方式參考AWS CLI安裝方式,就不再詳解,但要注意的是,在配置aws configure 時˙,[region name]必須指定SES區域才能夠抓到喔! IAM也要打開SES權限

  2. 開始在SES建立自訂驗證信件

    將下列這段範例,存在 C:\customverificationemail.json,路徑和名稱可以自己改
    {
      "TemplateName": "SampleTemplate",
      "FromEmailAddress": "sender@example.com",
      "TemplateSubject": "Please confirm your email address",
      "TemplateContent": "<html><head></head><body style='font-family:sans-serif;'><h1 style='text-align:center'>Ready to start sending email with ProductName?</h1><p>We here at Example Corp are happy to have you on board! There's just one last step to complete before you can start sending email. Just click the following link to verify your email address. Once we confirm that you're really you, we'll give you some additional information to help you get started with ProductName.</p></body></html>",
      "SuccessRedirectionURL": "https://www.example.com/verifysuccess",
      "FailureRedirectionURL": "https://www.example.com/verifyfailure"
    }


    參數定義↓

    屬性描述
    TemplateName範本名稱。您指定的名稱必須是唯一的。
    FromEmailAddress傳送驗證電子郵件的電子郵件地址。您指定的地址或網域必須經過驗證才可用於 Amazon SES 帳戶。
    注意
    FromEmailAddress 屬性不支援顯示名稱 (也稱為「友善寄件人」名稱)。
    TemplateSubject驗證電子郵件的主旨行。
    TemplateContent電子郵件內文。電子郵件內文可以在特定限制下包含 HTML。如需更多詳細資訊,請參閱 自訂驗證電子郵件常見問答集
    SuccessRedirectionURL如果電子郵件地址成功驗證,使用者將會收到此 URL。
    FailureRedirectionURL如果電子郵件地址未成功驗證,使用者將會收到此 URL。
  3. 檔案建立好後輸入

    aws ses create-custom-verification-email-template --cli-input-json file://C:\customverificationemail.json

    這裡我發現如果有中文的話指定file會告訴你他是binary,要改成fileb




    所以就改成

    aws ses create-custom-verification-email-template --cli-input-json fileb://C:\customverificationemail.json
  4. 完成後就可以測試寄發驗證信了

    aws ses send-custom-verification-email --email-address=<你的mail>  --template-name=<你自訂的template名稱>
  5. 收到信後點擊連結,mail驗證完成!!
  6. 如果要刪除舊的自訂template,可以輸入

    aws ses delete-custom-verification-email-template  --template-name=<你自訂的template名稱>

參考連結: AWS SES


留言

這個網誌中的熱門文章

[PHP] 正規表達式 過濾特殊符號 / 過濾非字母數字的字元 / 過濾字母數字