gpt4 book ai didi

c# - 设置 mimemessage 的正文会删除其他细节

转载 作者:太空宇宙 更新时间:2023-11-03 15:08:43 26 4
gpt4 key购买 nike

从我的 previous question 开始,如果我设置 MimeMessage 的正文,附件、正文部分和所有详细信息都会被删除。我该如何解决这个问题?

foreach (MimeKit.MimeEntity bodyPart in tnefMessage.BodyParts)
{
if (!bodyPart.IsAttachment)
{
using (MemoryStream ms = new MemoryStream())
{
bodyPart.WriteTo(ms);

ms.Flush();
ms.Position = 0;
using (StreamReader sr = new StreamReader(ms))
{
//Read in the contents until we get to the rtf
string line;
while (!(line = sr.ReadLine()).StartsWith("{") && !line.StartsWith("\\")) { }

tnefMessage.Body = new MimeKit.TextPart("plain")
{
Text = RTFToText($"{line}{sr.ReadToEnd()}")
};
}
}
}
}

static string RTFToText(string rtf)
{
string text = string.Empty;
System.Threading.Thread thread = new System.Threading.Thread(() =>
{
using (System.Windows.Forms.RichTextBox rtb = new System.Windows.Forms.RichTextBox())
{
rtb.Rtf = rtf;
text = rtb.Text;
}
});
thread.SetApartmentState(System.Threading.ApartmentState.STA);
thread.Start();
thread.Join();

return text;
}

最佳答案

这是因为你将正文设置为仅html,你需要将其设置为混合并重新添加附件:

Multipart multipart = new Multipart("mixed");
multipart.Add(new MimeKit.TextPart("plain")
{
Text = RTFToText($"{line}{sr.ReadToEnd()}")
});

foreach (MimeEntity attachment in tnefMessage.Attachments)
{
multipart.Add(attachment);
}

tnefMessage.Body = multipart;

关于c# - 设置 mimemessage 的正文会删除其他细节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42143144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com