Skip to content

Commit

Permalink
Improve Email Notification Message-ID and Threading Generation
Browse files Browse the repository at this point in the history
- Refactor email header generation for form submission notifications
- Use MD5 hashed submission ID for more consistent message threading
- Remove timestamp from Message-ID and Thread-Index generation
- Ensure emails are threaded only by submission ID
- Simplify header creation logic for better email client compatibility
  • Loading branch information
JhumanJ committed Mar 6, 2025
1 parent a59b466 commit 8894880
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions api/app/Notifications/Forms/FormEmailNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,24 @@ private function addCustomHeaders(Email $message): void
{
$formId = $this->event->form->id;
$submissionId = $this->event->data['submission_id'] ?? 'unknown';
$hashedSubmissionId = md5($submissionId);
$domain = Str::after(config('app.url'), '://');
$timestamp = time();

// Create a unique Message-ID for each submission
$messageId = "<form-{$formId}-submission-{$submissionId}-{$timestamp}@{$domain}>";

// Create a References header that links to the form, but not to specific submissions
$references = "<form-{$formId}@{$domain}>";
// Create a unique Message-ID for each submission (without timestamp)
$messageId = "<form-{$formId}-submission-{$hashedSubmissionId}@{$domain}>";

// Add our custom Message-ID as X-Custom-Message-ID
$message->getHeaders()->addTextHeader('X-Custom-Message-ID', $messageId);

// Add X-Entity-Ref-ID header for Google+ notifications
$message->getHeaders()->addTextHeader('X-Entity-Ref-ID', $messageId);

// Add References header
$message->getHeaders()->addTextHeader('References', $references);
// Add References header with the same value as Message-ID
// This ensures emails are only threaded by submission ID, not by form ID
$message->getHeaders()->addTextHeader('References', $messageId);

// Add a unique Thread-Index to further prevent grouping
$threadIndex = base64_encode(pack('H*', md5($formId . $submissionId . $timestamp)));
$threadIndex = base64_encode(pack('H*', md5($formId . $submissionId)));
$message->getHeaders()->addTextHeader('Thread-Index', $threadIndex);
}

Expand Down

0 comments on commit 8894880

Please sign in to comment.