Relaying message sends it to the CC/BCC recipients even when recipients were overridden
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(); }
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.
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
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.
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:
- to: [email protected],
- cc: [email protected]
- bcc: [email protected]
(and all of these were used in the
RCPT TOenvelope when smtp4dev received the message.)
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.