简体   繁体   中英

How to set content transfer encoding using MimeKit/MailKit?

I try to send text in attachment. That works well only right now i have encoding problems in the builder.ToMessageBody() statement (see code below) Itry to send an email with text "my text = my subject and Version=1.0" as attachment, but when you open the email the text has been altered to "my text =3D my subject and Version=3D1.0". As you can see the = sign has been encoded to =3D Is there a way to change the encoding? Thanks

var message = new MimeMessage();
var builder = new BodyBuilder();

builder.TextBody = "";
var xmltext ="my text = my subject and Version=1.0" ;

builder.Attachments.Add("12345.txt", Encoding.ASCII.GetBytes(xmltext), new ContentType("text", "plain"));

message.Body = builder.ToMessageBody();

The Add method actually returns the MimeEntity that it creates, allowing you to make changes to it.

To force the encoding to base64, for example, you can do this:

var attachment = (MimePart) builder.Attachments.Add("12345.txt", Encoding.ASCII.GetBytes(xmltext), new ContentType("text", "plain"));
attachment.ContentTransferEncoding = ContentENcoding.Base64;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM