2
votes

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?

1
What do you mean by : I cannot attribute complaints and bounces to a specific email message? Specifically what "complaints"? Are you trying to use the response codes to determine if the email was successfully delivered?AgRizzo
I cannot attribute complaints and bounces to a specific email message? Specifically what "complaints"? Email feedback complaints, particularly spam complaints. Are you trying to use the response codes to determine if the email was successfully delivered? No, I'm trying to pull the message-id out of the response message. Amazon takes the message-id that CakeEmail generates, and rewrites it. This is for their internal tracking purposes. They return that ID to you in the response message "250 Ok ****message ID****". Then SES uses that message-ID to report any complaints or bounces.billybobmac
Does the return value of the send method have the 250 response code - i.e., $result = $Email->send();?AgRizzo
I tried that. It passes an array of the headers and message. The message-id header passed is the message-id before SES rewrites it.billybobmac
Did you try working with sns notifications?alexandresaiz

1 Answers

1
votes

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