Reputation: 31
I'm using CakePHP 2.6 and using CakeEmail to send a verification email to users.
$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']);
As Amazon SES rewrites the message-id, I cannot attribute complaints and bounces to a specific email message. According to their docs, Amazon SES returns the message ID in the final SMTP response. I.e.(250 Ok <Message ID>)
How can I retrieve that response code?
Upvotes: 3
Views: 775
Reputation: 190
With Cake 3.x We can get with this
$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
)
Upvotes: 0
Reputation: 394
On line 316 of ./vendor/cakephp/cakephp/lib/Cake/Network/Email/SmtpTransport.php if you add a third element to the array returned after you send a mail with the standard CakePHP Smtp transport you can force the last response from SES to be returned thereby giving you the ID link to attribute AWS SNS delivery notifications, bounces or complaints.
$this->_content = array('headers' => $headers, 'message' => $message, 'response' => $this->_lastResponse);
'response' then provides...
Array(
[code] => 250
[message] => Ok 00000151379549a4-6e36766f-849e-4e3c-9ac9-6ac1c6ad5434-000000
)
Suggest you duplicate/mimic the Smtp transport to avoid that hack being overwritten as you update CakePHP (http://book.cakephp.org/2.0/en/core-utility-libraries/email.html#creating-custom-transports).
From the e-mail itself:
Message-ID: <0000015137aa362a-f53a549b-9420-4056-8623-c24ecf8785de-000000@eu-west-1.amazonses.com>
Grab the actual Message ID with this:
$message['Email']['message_id'] = preg_replace('/Ok /', '', $response['response'][0]['message']);
Upvotes: 1