Roman Traistari
Roman Traistari

Reputation: 81

How to avoid MailKit changing transfer encoding of text/plain and text/html parts?

I'm using MimeMessage.Load() and SmtpClient.Send() to load and send .eml files. Problem is that MailKit changes UTF-8 text/plain part with no transfer encoding to UTF-8 with base64, and text/html part with UTF-8 and no transfer-encoding is changed into UTF-8 with quoted-printable. Can this be avoided? Ideally, I would like to send the eml files exactly as they are, with only minimal changes to To and From headers.

Upvotes: 0

Views: 1406

Answers (1)

jstedfast
jstedfast

Reputation: 38538

Before sending a message, MailKit's SmtpClient will Prepare the message for transport given the SMTP server's encoding constraints (which are either: 7bit, 8bit, or binary depending on what the server supports).

The SmtpClient's Prepare() method is virtual and so can be overridden.

The default implementation essentially just calls MimeMessage.Prepare.

What this method does is walks the tree of MIME parts making sure that every MIME part has content that adheres to the encoding constraint provided. If and when it finds a part that does not conform, it calculates the best Content-Transfer-Encoding to use and then sets that.

Upvotes: 1

Related Questions