Removing commas from outbound email message
SMTP email proxy and relay server
Brought to you by:
graeme_walker
We are using EmailRelay to accept messages from a voicemail to email gateway. Microsoft is bouncing select messages that we send from EMR because the subject line of some messages includes one or more commas.
We'd like to see a way to strip any commas that might appear in the subject line before EMR forwards to the SMTP server.
So as per our DM, I would suggest using the example filter script "emailrelay_set_from.js" as a starting point for editing header fields such as "Subject:".
I've attached a version that removes subject commas, but you might want to change the 'replacement' variable to be a space or an underscore or whatever.
You will need to add a "--filter" option to the emailrelay command-line that refers to the filter script, typically as a "filter ...." line in the "emailrelay.cfg" configuration file.
I don't think it will be relevant to your situation, but "Subject:" headers sometimes use fancy encoding like "Subject: =?UTF-8?B?ZmFuY3kgc3ViamVjdA?=", which the attached script will not handle.
Thank you for the script.
I went back and forth with the upstream email provider (SMTP2Go) and now they are changing their story. It's not the comma in the subject causing a problem, it's a comma in the FROM field that MailRelay is accepting and then passing to the next hop.
SMTP2Go support sent me an example of a header that is problematic:
Received: from 10.15.241.108
by smtpcorp.com with esmtpa (Exim 4.97.1-S2G)
(envelope-from voicemail@domainname.org)
id 1u6ys0-4o5NDgrv5fh-dDl3
for <redacted>
Mon, 21 Apr 2025 21:40:04 +0000
Received: from uc-module ([192.168.12.231]) by PC-UTILITY2024.localnet with ESMTP ; Mon, 21 Apr 2025 17:39:47 -0400
From: HURST,NORMAN voicemail@domainname.org
To: >REDACTED>
Subject: Voicemail Message (HURST,NORMAN > Robert A) From: REDACTED PHONE#
Date: Mon, 21 Apr 2025 17:44:39 -0400
X-Mailer: Voicemail Pro Server
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="{872065bb-9374-cf4d-9ce4-7cc68f011431}"
Content-Transfer-Encoding: quoted-printable
X-Priority: 3
X-MSMail-Priority: Normal
Priority: Normal
Importance: Normal
Sensitivity: Normal
Content-Class: voice
X-CallingTelephoneNumber: <redacted>
X-VoiceMessageDuration: 33
X-VoiceMessageSenderName: HURST,NORMAN
X-VoiceMessageOffset: 72
X-VoiceMessageReceivedTime: 3922474264
X-AttachmentOrder: ;MSG02017.WAV
X-MS-Has-Attach: yes
Message-Id: E1u6ys0-4o5NDgrv5fh-dDl3@message-id.smtpcorp.com</redacted></redacted>
The issue is the comma here:
From: HURST,NORMAN voicemail@domainname.org
Apparently Microsoft interprets the comma as meaning multiple FROM addresses which they do not permit.
To keep this easy, is there a way to discard the FROM value that EMailRelay gets from the client and just "hard code" a value? Say voicemail@domainname.org ??
Yes, that's even easier: use the example script "emailrelay-set-from.js" as the "--filter" script. Edit the "new_from" variable as required.
From what you have said you should only need to edit the "From:" header in the message content using the "emailrelay-set-from.js" filter script (as discussed), but for completeness I have also attached a new script (based on "emailrelay-edit-envelope.js") to set the 'from' address in the envelope. Edit it to set the required address and run both scripts using two separate "--filter" command-line options or two separate "filter" lines in the configuration file.