Mailkit: Need option to remove sender header from message.

Created on 26 Sep 2019  路  2Comments  路  Source: jstedfast/MailKit

Is your feature request related to a problem? Please describe.
When I add the sender MailboxAddress it changes the MAIL FROM in the envelope but also adds a sender header. The problem is that in some email clients and in particular, Outlook, the client displays something like "[email protected] on behalf of [email protected]" or "Sender sender@domain.com on behalf of From from@domain.com". This may be correct but the recipient is often left in doubt as to who the message is really from. Typically the sender is going to be used to handle NDRs programmatically using a VERP (Variable envelope return path) scheme and the alias part of the address could be a GUID.

Describe the solution you'd like
I would like an option to not add the sender header, and only change the MAIL FROM in the envelope. Perhaps adding the sender to the MimeMessage should add the header but adding it in the MailTransport.SendAsync overload does not?

Describe alternatives you've considered
The only way I've found to get what I want so far is to extend the SmtpClient and remove the header from the Prepare method:

public class ExtendedSmtpClient : SmtpClient
{
    protected override void Prepare(FormatOptions options, MimeMessage message, EncodingConstraint constraint, int maxLineLength)
    {
        message.Headers.Remove(HeaderId.Sender);

        base.Prepare(options, message, constraint, maxLineLength);
    }
}

I haven't fully tested this but I'm wondering if there's a better way you could point out to me?

Additional context
Amazon SES modifies the MAIL FROM without adding the sender header so I guess this is considered acceptable practice.

Please let me know what you think.
Thanks
Andrew

question

Most helpful comment

Doh! I think I tried every combination except the most obvious one! MimeKit and MailKit are outstanding libraries. Thank you.

All 2 comments

Use SmtpClient.Send (message, from, recipients);

Doh! I think I tried every combination except the most obvious one! MimeKit and MailKit are outstanding libraries. Thank you.

Was this page helpful?
0 / 5 - 0 ratings