My Laravel application has a ticket system included, which is sending email notifications.
All emails are built and sent like this one:
public function build()
{
$email_from_name = "Support - " . config('app.name');
$subject = "[" . $this->ticket->id . "] " . $this->ticket->subject . " - " . config('app.name');
return $this->from('[email protected]', $email_from_name)
->subject($subject)
->markdown('emails.customer.ticket.comment_added')
->with([
'nickname' => $this->user->nickname,
'ticket_id' => $this->ticket->id,
'ticket_subject' => $this->ticket->subject,
'ticket_text' => $this->ticket_comments->text,
]);
}
Unfortunately, when I get multiple of these emails, no email client (Outlook, Thunderbird, Roundcube,...) shows these emails as thread / conversation. All clients show each email as "new email" thread / conversation.
What specifies, that some emails are one thread / conversation and some not? How can I tell my Laravel application, that these emails are one thread / conversation?
I thought, it just needs to be the same email subject, but it doesn't work.
Thanks to @Yeeooow for the information regarding the
RFC 2822
standard:The References and In-Reply-To headers must be set in compliance with the RFC 2822 standard.
Based on these information, I've checked some other email threads / conversations, which I had. All of these used the mentioned
References
andIn-Reply-To
headers in the same way. With this information, I've started developing to archive the same result.Due of the fact, that we need to reference to old emails, we need a table, where we can store the
Message-ID
of each sent email. I've created this table in my case:With this table, we're able to store the
Message-ID
of each sent email and can reference to which ticket it belongs to. This will help us later also to get only associatedMessage-ID
s related to this ticket - otherwise, we'll mix up different ticket histories in the same email thread.Into the
reference_id
field, you can optionally store the associated ID of the task:In your mailable (eg.
app\Mail\TicketTextAdded.php
), you can now add the code section$this->withSwiftMessage() {}
into yourbuild()
function to capture the currentMessage-ID
of this new email and reference to all other emails before as well as store the new Message-ID`:FYI: You could also change the
Message-ID
there, where we've set the custom headers, but this needs to comply to the relevant RFC documents:Further information: https://swiftmailer.symfony.com/docs/headers.html#id-headers
Hopefully, I could help somebody else with these information. :)