为了账号安全,请及时绑定邮箱和手机立即绑定

将电子邮件另存为 .eml 并包含原始 email.body

将电子邮件另存为 .eml 并包含原始 email.body

C#
守着星空守着你 2023-09-16 17:17:41
我使用以下代码保存我的Emailusing api。EWS但是,当我打开保存的.eml格式时.mht,它是带格式的全文<tags>。有没有办法保存 的原始HTML格式email.Body和原始外观?private static void saveEmailAsEML(EmailMessage email){    {        string to = "test@mail.com";        string from = "test@mail.com";        string subject = "test subject";        string body = email.Body.();        string emailDir = @"C:\\Temp\\Email";        string msgName = @"email.eml";        Console.WriteLine("Saving e-mail...");        using (var client = new SmtpClient())        {            MailMessage msg = new MailMessage(from, to, subject, body);            client.UseDefaultCredentials = true;            client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;            client.PickupDirectoryLocation = emailDir;            try            {                client.Send(msg);            }            catch (Exception ex)            {                Console.WriteLine("Exception caught: {0}",                ex.ToString());                Console.ReadLine();                System.Environment.Exit(-1);            }        }        var defaultMsgPath = new DirectoryInfo(emailDir).GetFiles()          .OrderByDescending(f => f.LastWriteTime)          .First();        var realMsgPath = Path.Combine(emailDir, msgName);        try        {            File.Move(defaultMsgPath.FullName, realMsgPath);            Console.WriteLine("Message saved.");        }        catch (System.IO.IOException e)        {            Console.WriteLine("File already exists. Overwrite it ? Y / N");            var test = Console.ReadLine();            if (test == "y" || test == "Y")            {                Console.WriteLine("Overwriting existing file...");                File.Delete(realMsgPath);                File.Move(defaultMsgPath.FullName, realMsgPath);                Console.WriteLine("Message saved.");            }
查看完整描述

1 回答

?
宝慕林4294392

TA贡献2021条经验 获得超8个赞

您实际上是从一些属性重新组装消息。为什么不获取整个 MIME 消息(包含所有标头、附件等)?

查看完整回答
反对 回复 2023-09-16
  • 1 回答
  • 0 关注
  • 56 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信