jdavidbakr / mail-tracker

Package for Laravel to inject tracking code into outgoing emails.
MIT License
567 stars 129 forks source link

Different message ID when sending via SES #163

Closed louis-l closed 2 years ago

louis-l commented 2 years ago

Hi there,

I have a need to use the sent email message ID and I start looking into the sent_emails table and realized in headers column, there is a Message-ID key that has different value comparing to one in message_id column.

For instance:

I also checked the meta column, and both IDs appear there as well:

{
  "smtpResponse": "250 2.0.0 OK  1646870409 p2-20020a1709026b8200b0014f1c918957si2953939plk.484 - gsmtp",
  "success": true,
  "delivered_at": "2022-03-10T00:00:10.099Z",
  "sns_message_delivery": {
    "notificationType": "Delivery",
    "mail": {
      "timestamp": "2022-03-10T00:00:07.463Z",
      ...
      "messageId": "0108017f71202927-4718d6c3-8547-4f89-a995-fa9a5d16749c-000000",
      "headersTruncated": false,
      "headers": [
        {
          "name": "Message-ID",
          "value": "<19af1c41dbb91e5df0f5ba9cb9eaed7b@swift.generated>"
        },
        {
          "name": "Date",
          "value": "Thu, 10 Mar 2022 00:00:07 +0000"
        },
        ...
      ],
      "commonHeaders": {
        "from": [
          "..."
        ],
        "date": "...",
        "to": [
          "..."
        ],
        "messageId": "<19af1c41dbb91e5df0f5ba9cb9eaed7b@swift.generated>",
        "subject": "..."
      }
    },
    "delivery": {
      "timestamp": "2022-03-10T00:00:10.099Z",
      ...
    }
  }
}

So my question is: which one is the actual ID?

Cheers,

jdavidbakr commented 2 years ago

The message ID in the headers is the one that is generated by swift. For SES, the message_id is set to the value in mail->messageId that is set by SES so that it can track SES events.

louis-l commented 2 years ago

Thanks @jdavidbakr

So does that mean the actual ID got sent out is message_id? If I want to pass the message ID to "References" and "In-Reply-To" headers, I should use the message_id in sent_emails table, right?

jdavidbakr commented 2 years ago

I'm not fully understanding what you are asking. Are you trying to do something like this? https://github.com/jdavidbakr/mail-tracker#passing-data-to-the-event-listeners

louis-l commented 2 years ago

@jdavidbakr

Yes, Im trying to do this:

$message->getHeaders()->addTextHeader('References', 'previous_message_id');
$message->getHeaders()->addTextHeader('In-Reply-To', 'previous_message_id');

I need to retrieve the previous_message_id from sent_emails table.