0
使用下面的代碼Winmail.dat文件的RTF主體作爲附件添加到保存的電子郵件沒有身體:Mimekit添加RTF格式作爲附件,而不是身體
using (Stream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None))
{
MimeKit.MimeMessage mimeMessage = MimeKit.MimeMessage.Load(stream);
int i = 1;
foreach (MimeKit.MimePart attachment in mimeMessage.Attachments)
{
if (attachment.GetType() == typeof(MimeKit.Tnef.TnefPart))
{
MimeKit.Tnef.TnefPart tnefPart = (MimeKit.Tnef.TnefPart)attachment;
MimeKit.MimeMessage tnefMessage = tnefPart.ConvertToMessage();
tnefMessage.WriteTo(path + $"_tnefPart{i++}.eml");
}
}
}
我怎麼能解決這個問題?
展望Attachments
它不存在有,但附件和body.rtf文件存在於BodyParts
。所以,我可以得到body.rtf文件是這樣的:
int b = 1;
foreach (MimeKit.MimeEntity bodyPart in tnefMessage.BodyParts)
{
if (!bodyPart.IsAttachment)
{
bodyPart.WriteTo(path + $"_bodyPart{b++}.{bodyPart.ContentType.MediaSubtype}");
}
}
邊注:是的body.rtf文件是不正確的RTF,因爲它具有以下開始:
內容-Type:text/rtf;名稱= body.rtf
(新線)