我使用CakePHP 2.6,并使用CakeEmail向用户发送验证电子邮件。
$Email = new CakeEmail('smtp');
$Email->to($this->request->data['Account']['account_email']);
$Email->subject('Verify your account before you continue');
$Email->send('http://localhost/Accounts/verify/'.$this->request->data['Account']['account_verificationhash']);
由于亚马逊SES重写了消息id,我无法将投诉和反弹归因于特定的电子邮件。根据他们的文档,AmazonSES在最后的SMTP响应中返回消息ID。即(250 Ok <Message ID>)
如何检索响应代码?
在的第316行/vendor/cakehp/cakehp/lib/Cake/Network/Email/SmtpTransport.php如果您在使用标准cakephp-Smtp传输发送邮件后向返回的数组中添加第三个元素,则可以强制返回SES的最后一个响应,从而为您提供ID链接,将AWS SNS交付通知、反弹或投诉归为属性。
$this->_content = array('headers' => $headers, 'message' => $message, 'response' => $this->_lastResponse);
"response"然后提供。。。
Array(
[code] => 250
[message] => Ok 00000151379549a4-6e36766f-849e-4e3c-9ac9-6ac1c6ad5434-000000
)
建议您复制/模拟Smtp传输,以避免在更新CakePHP时覆盖该破解(http://book.cakephp.org/2.0/en/core-utility-libraries/email.html#creating-自定义运输)。
来自电子邮件本身:
消息ID:<0000015137aa362a-f53a549b-9420-4056-8623-c24ecf8785de-000000@eu-west-1.amazonses.com>
用这个获取实际的消息ID:
$message['Email']['message_id'] = preg_replace('/Ok /', '', $response['response'][0]['message']);
用Cake 3.x我们可以用这个
$email = new Email();
// Use a named transport already configured using Email::configTransport()
$email->setTransport('amazonses');
$email->send($html);
debug($email->getTransport()->getLastResponse());
Array(
[code] => 250
[message] => Ok 00000151379549a4-6e36766f-849e-4e3c-9ac9-6ac1c6ad5434-000000
)