Overview
Outgoing order and system emails sent by Sellerdeck should include a Message-Id header, as required by the email standard (RFC 5322). Without one, some receiving mail servers and spam filters will reject or flag emails sent via Secure SMTP, which can result in order confirmations, despatch notes, or other customer emails failing to arrive.
Secure SMTP was introduced in v18.0.0, and a Message-Id header is not added automatically. This article shows you how to modify SmtpLibrary.pm so that a unique Message-Id is generated and sent with every email.
Applies to: All v18 releases (18.0.0 and later), using Secure SMTP.
Before you start
Step 1: Update the mail header block
Open SmtpLibrary.pm in a text editor and locate the following lines. Depending on your version, the middle line may already be present:
Replace these three lines with the following four lines:
Step 2: Send the Message-Id header on the socket
Next, locate the following block of code. Make sure you have the right one by checking that it refers to Date: $sNow:
Immediately after this block, insert the following new block:
Step 3: Add the GetUniqueMailId subroutine
Finally, scroll to the end of the file and paste the following block of code immediately before the final 1; line:
Save the file once all three changes have been made.
Testing
Adding a Message-Id header brings Secure SMTP email sending in v18 in line with the RFC 5322 email standard and can help prevent outgoing emails from being rejected or flagged as spam by receiving mail servers. This change only needs to be made once per site.
Outgoing order and system emails sent by Sellerdeck should include a Message-Id header, as required by the email standard (RFC 5322). Without one, some receiving mail servers and spam filters will reject or flag emails sent via Secure SMTP, which can result in order confirmations, despatch notes, or other customer emails failing to arrive.
Secure SMTP was introduced in v18.0.0, and a Message-Id header is not added automatically. This article shows you how to modify SmtpLibrary.pm so that a unique Message-Id is generated and sent with every email.
Applies to: All v18 releases (18.0.0 and later), using Secure SMTP.
Before you start
- These changes involve editing a Perl file used by your site, so we recommend making a backup copy of SmtpLibrary.pm before you begin.
- SmtpLibrary.pm is located in your site's Site folder — the same folder as your site's other Perl library files (typically under your SellerDeck installation's Sites\<YourSite> folder).
- If you are not comfortable editing Perl code directly, ask your web designer or a Sellerdeck partner to make these changes for you.
Step 1: Update the mail header block
Open SmtpLibrary.pm in a text editor and locate the following lines. Depending on your version, the middle line may already be present:
Code:
"Subject: ".encode('MIME-Header', $mail_subject)."\n".
"Date: $sNow\n";
"MIME-Version: 1.0\n";
Code:
"Subject: ".encode('MIME-Header', $mail_subject)."\n".
"Date: $sNow\n".
"Message-Id: " . GetUniqueMailId()."\n".
"MIME-Version: 1.0\n";
Step 2: Send the Message-Id header on the socket
Next, locate the following block of code. Make sure you have the right one by checking that it refers to Date: $sNow:
Code:
unless (print MYSOCKET "Date: $sNow\r\n") # Date
{
RecordErrors(GetPhrase(-1, 18, 5, $!)); # Record internal error
close MYSOCKET;
return($::FAILURE, $::sMemoryLog);
}
Code:
unless (print MYSOCKET "Message-Id: " . GetUniqueMailId() . "\r\n") # Message ID
{
RecordErrors(GetPhrase(-1, 18, 5, $!)); # Record internal error
close MYSOCKET;
return($::FAILURE, $::sMemoryLog);
}
Finally, scroll to the end of the file and paste the following block of code immediately before the final 1; line:
Code:
################################################################
#
# GetUniqueMailId - get a unique message ID
# uses random characters, time and host name
#
# Code derived from Email::MessageID 1.406 by Ricardo Signes
# http://cpansearch.perl.org/src/RJBS/Email-MessageID-1.406/lib/Email/MessageID.pm
#
# Returns: unique message ID
#
################################################################
sub GetUniqueMailId
{
use Sys::Hostname qw/hostname/;
my @CHARS = ('A'..'F','a'..'f',0..9);
my %uniq;
my $noise = join '',
map {; $CHARS[rand @CHARS] } (0 .. (3 + int rand 6));
my $t = time;
my $u = exists $uniq{$t} ? ++$uniq{$t} : (%uniq = ($t => 0))[1];
my $user = join '.', $t . $u, $noise, $$;
return '<' . $user . '@' . hostname . '>';
}
Testing
- Place a test order on your site.
- Check the raw headers of the received email — most mail clients offer a "view source" or "show original" option — and confirm a Message-Id: header is present, in the form <...@yourhostname>.
- It should look something like....
Code:
Date: 23 Aug 2024 16:22:48 GMTMessage-Id: <17244301680.c1b58bd4b.10068@test001.sellerdeckwebhosting.co.uk>MIME-Version: 1.0
- It should look something like....
- If emails were previously being blocked or marked as spam, monitor for a few days to confirm delivery has improved.
Adding a Message-Id header brings Secure SMTP email sending in v18 in line with the RFC 5322 email standard and can help prevent outgoing emails from being rejected or flagged as spam by receiving mail servers. This change only needs to be made once per site.