Skip to content

[charcoal/email] Broken tracker ID logic #76

@mcaskill

Description

@mcaskill

Transcribed from a conversation from 2022-02-24:

Chauncey:
Non-urgent but important flaw in Email::logSend() introduced in locomotivemtl/charcoal-email#7c230fb:

If your email has more than one recipient, the SQL database will throw an exception when trying to insert a log of the second recipient because the log ID does not change:

Failed SQL query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'XXXXXXXX' for key 'PRIMARY'

Bene:
I had already spoken to Mat about it, it was introduced with the addition of the email tracker. The ID is generated before for the tracker but that would create this problem and this whole portion would have to be refactored but I was unsure on the avenue to take

Chauncey:
Yeah, we’d need a dedicated column for this shared ID.

Bene:
We probably want different tracking IDs for the recipients to be accurate but not necessarily different IDs for the send log.

Chauncey:
Hrm. Yeah, ideally, a unique tracking ID for each recipient, which would require refactoring the $mail->send() portion, iterate over each recipient ourselves in Email::send().

Something like this: https://stackoverflow.com/a/41563520/140357

Prepare PHPMailer object, than in Email::send() iterate over each recipient ourselves, clearing the previously iterated recipient and body.

PHPMailer generates the message ID itself, maybe we could take advantage of that to create a two-part ID (<uniqueMessageID>-<groupMessageID>@<serverHostName>):

For example, Symfony’s message ID generator:
https://github.com/symfony/symfony/blob/60ce5a3dfbd90fad60cd39fcb3d7bf7888a48659/src/Symfony/Component/Mime/Message.php#L138-L149

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions