cakephp 通过SMTP在Amazon SES上使用CakeEmail检索Message-Id

w9apscun  于 2023-04-12  发布在  PHP
关注(0)|答案(2)|浏览(220)

我使用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']);

由于Amazon SES重写了message-id,我无法将投诉和退回归因于特定的电子邮件。根据他们的文档,Amazon SES在最终的SMTP响应中返回邮件ID。即(250 Ok <Message ID>)
如何检索该响应代码?

oewdyzsn

oewdyzsn1#

在./vendor/cakephp/cakephp/lib/Cake/Network/Email/SmtpTransport.php的第316行,如果您在使用标准CakePHP Smtp传输发送邮件后向返回的数组中添加第三个元素,则可以强制返回SES的最后一个响应,从而为您提供指向AWS SNS交付通知、退回或投诉属性的ID链接。

$this->_content = array('headers' => $headers, 'message' => $message, 'response' => $this->_lastResponse);

“响应”则提供…

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-custom-transports)。
电子邮件本身:
Message-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']);
f8rj6qna

f8rj6qna2#

有了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
)

相关问题