我使用以下代码保存我的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.");
}
宝慕林4294392
相关分类