我使用以下代碼保存我的Emailusing api。EWS但是,當我打開保存的.eml格式時.mht,它是帶格式的全文<tags>。有沒有辦法保存 的原始HTML格式email.Body和原始外觀?private static void saveEmailAsEML(EmailMessage email){ { string to = "[email protected]"; string from = "[email protected]"; 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 回答
- 0 關注
- 116 瀏覽
添加回答
舉報
0/150
提交
取消