smtp4dev icon indicating copy to clipboard operation
smtp4dev copied to clipboard

Relaying message sends it to the CC/BCC recipients even when recipients were overridden

Open pcooneyatuconn opened this issue 2 years ago • 4 comments

When forwarding a 'trapped' email, if the message had a CC/BCC, it would continue send it to those recipients. I wanted the email relayed/forwarded to the email addrs typed in the list.

My fix - in Smtp4devServer.cs @ lines 343 added if (overrideRecipients != null) { newEmail.Cc.Clear(); newEmail.Bcc.Clear(); }

pcooneyatuconn avatar Jun 26 '23 18:06 pcooneyatuconn

When we are relaying the message to the upstream server, in the "envelope" we're using either the original recipients or those entered to overrride. The actual message contains the original to/cc headers which you will see when the message is delivered and may contain other recipients, but the upstream server shouldn't act and deliver to all of those.

If you think it's doing something other than this, please can you share a bit more info like a specific .eml example and the output you see in the console when smtp4dev is relaying.

rnwood avatar Feb 25 '24 12:02 rnwood

Rob.. I removed my code snippet and and did a little debug for you. smtp4dev_CC.BCC_Issue.docx

Hopefully you can look at docx files.. if not let me know

--Patrick

pcooneyatuconn avatar Feb 26 '24 13:02 pcooneyatuconn

Thanks. That makes it clear what is happening. The Mailkit recipients argument doesn't override the CC and BCC, which is surprising.

So your fix makes total sense. But it should be applied to the non override recipient case too because we should only be delivering to those from the envelope rather than who's on the message inside.

I will make this change soon.

rnwood avatar Feb 26 '24 16:02 rnwood

The Mailkit recipients argument doesn't override the CC and BCC, which is surprising.

I jumped to a conclusion about this. Actually, it does override all the recipients in what it sends to the SMTP server as RCPT TO but it leave the actual message headers alone. So when you are looking at the message you will see these as to/cc headers but the server should not actual deliver it to them unless in the RCPT TO.

To test this, I relayed a message with:

I chose the option to relay and chose only [email protected]:

Relaying message to [email protected]

Log from the relay server:

MAIL FROM:<[email protected]>
250 New message started
RCPT TO:<[email protected]>
250 Recipient accepted
DATA
354 End message with period
MIME-Version: 1.0
From: [email protected]
To: [email protected]
Cc: [email protected]
Date: 26 Feb 2024 17:15:26 +0000
Subject: Message 1

Notice in the actual message you can see to: and cc: headers, but in the RCPT TO it's only the address I chose.

rnwood avatar Feb 26 '24 17:02 rnwood