【问题标题】:ColdFusion and AWS SESColdFusion 和 AWS SES
【发布时间】:2015-01-02 18:57:50
【问题描述】:

我正在尝试使用 Amazon 的 SES 设置我的 CF 服务器,但我想我做错了什么......

这就是我到目前为止所做的

• 从我的 AWS 控制台创建凭证
• 在我的 CF 管理员中添加了必要的设置(服务器、端口、用户/密码)
• 创建了一个测试脚本
• 没有出现任何错误
• 未收到任何电子邮件,并且根据我的 AWS SES 控制台,未发送任何电子邮件。

任何曾经在 CF 上使用过此服务的人都可以为我指出正确的方向,我将不胜感激。

【问题讨论】:

  • 您有关于您的测试脚本的详细信息吗?它试图做什么? <cfmail> ?
  • 我解决了这个问题。还有另一个面板,您必须在其中验证出站电子邮件的电子邮件地址以及您发送的域。现在好了:)
  • 你应该发布一个带有截图的答案,这样如果其他人卡在这个问题上,他们就会知道该怎么做
  • 有帮助吗?当我写这篇文章时,我自己的设置有问题,但一切都解决了。
  • 我的绊脚石,如果它对看到这篇文章的其他人有帮助,与用户名和密码有关。它不是进入那里的密钥/秘密组合,而是用户名和密码。通过 IAM 为 SES 创建一个新用户,授予该用户 SES 权限,并使用实际的用户名和密码进行 CFAdmin 邮件设置。我使用了 587 端口并成功启用了 TLS。

标签: amazon-web-services coldfusion amazon-ses coldfusion-11


【解决方案1】:

下面的代码使用CFMail标签。它允许使用 CFHTTP POST 将原始格式的电子邮件、日历邀请等发送到 AWS SES,而不受 CFMAIL 标签的限制。如果您想使用 CFMail TAG,请参阅 AWS 配置 SMTP 服务器的说明。

在实现以下代码之前,请先获取以下内容:

  1. Refer to <cfLove/> Sending emails with Amazon SES API SendRawEmail in ColdFusion to construct raw email message

  2. Reference to Leigh Sv4Util.cfc for AWS v4 Signing

 NOTE: in the V4 Signing cfc -- CF16 returns the AMZDate as +0000
 for zulu. Find AMZDate (2 places) change to LEFT(AMZDate, 15) & "Z" to force
 the to end in Z -- 20200930T222905+0000 -> 0200930T222905Z.
  1. Refer to AWS for Sample SES Post

下面的示例代码假定 attributes.mail 是根据 CFLove 的示例代码格式化的,并且您正在使用 Sv4Util.cfc 进行签名。

<!--- This is sample code for send to AWS SES as Raw Data Send post --->



<!--- Init Signing CFC --->
<cfset LocalVar.s4 = CreateObject('component', 'Sv4Util.cfc').init(
  accessKeyId = attributes.AWSKey
, secretAccessKey = attributes.AWSSecretKey
, defaultRegionName = attributes.AWSRegion
, defaultServiceName = "ses"
)>


<!--- 
  Refer to https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html 
  AWS Post Example Requirements
   - Action
   - Destinations.members.?
   - Source
   - RawMessage.Data
--->

<cfset PL           = {}>
<cfset PL['Action'] = "SendRawEmail">
   

<!--- List of Email Addresses --->
<cfset count = 1>
<cfloop list="#attributes.deliverto#" index="i">
       <cfset PL["Destinations.members.#count#"] = i>
       <cfset count = count + 1>
</cfloop>

<!--- From --->
<cfset PL["Source"]          = trim(attributes.from)>

<!--- The RAW MESSAGE -- Must be encoded due to BASE64 ending with an = --->
<cfset PL["RawMessage.Data"] = URLEncodedFormat(ToBase64(trim(ArrayToList(attributes.mail,chr(10)))))>


<!--- Build URL format string for posting the above struct (PLS) --->
<cfset PLS = ''>
<cfloop list="#ListSort(structKeyList(PL), 'text', 'asc')#" index="i" >
       <cfset PLS = ListAppend(PLS,  i & "=" & PL[i], "&")>
</cfloop>

<!--- Sign Request --->
<cfset LocalVar.Signing = LocalVar.s4.generateSignatureData(  
                          requestMethod = 'POST' <!--- UPPER CASE --->
                        , hostName = 'email.#attributes.AWSRegion#.amazonaws.com'
                        , requestURI = ''
                        , requestBody = PLS
                        , requestHeaders = {"content-type":"application/x-www-form-urlencoded"}
                        , requestParams = {}
                        )>


<!--- Do POST to AWS --->
<!--- Required in POST 
      - x-amz-content-sha256
      - Authorization
      - x-amz-date
      - content-type
      - body
--->      
<cfhttp url="https://email.#attributes.AWSRegion#.amazonaws.com" method="post" result="result">  
   <cfhttpparam type="header" name="x-amz-content-sha256"    value="#LocalVar.Signing.RequestPayLoad#" />
       <cfhttpparam type="header" name="Authorization"        value="#LocalVar.Signing.authorizationHeader#" />
       <cfhttpparam type="header" name="x-amz-date" value="#LocalVar.Signing.AMZDate#" />
       <cfhttpparam type="header" name="content-type" value="application/x-www-form-urlencoded" />
       <cfhttpparam type="body" value="#PLS#" />        
</cfhttp>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 1970-01-01
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 2018-08-12
    相关资源
    最近更新 更多