简体   繁体   English

如何使用 MimeKit/MailKit 设置内容传输编码?

[英]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".这只适用于现在我在 builder.ToMessageBody() 语句中有编码问题(见下面的代码)我尝试发送一个 email 作为附件,文本“我的文本 = 我的主题和版本 = 1.0”,但是当你打开 email文本已更改为“我的文本 =3D 我的主题和版本 =3D1.0”。 As you can see the = sign has been encoded to =3D Is there a way to change the encoding?如您所见,= 符号已被编码为 =3D 有没有办法更改编码? 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. Add方法实际上返回它创建的MimeEntity ,允许您对其进行更改。

To force the encoding to base64, for example, you can do this:例如,要强制编码为 base64,您可以这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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