将电子邮件另存为原始文件 email.body 的 .eml
Save Email as .eml with original email.body
我正在使用 EWS
api 使用以下代码保存我的 Email
。但是,当我打开保存的 .eml
和 .mht
格式时,它是格式为 <tags>
.
的全文
有没有办法将 email.Body
的原始 HTML
格式保存为原始外观?
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.");
}
else
{
Console.WriteLine("Exiting Program without saving file.");
}
}
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
}
您实际上是在从几个属性中重新组合消息。为什么不获取整个 MIME 消息(包括所有 headers、附件等)?
我正在使用 EWS
api 使用以下代码保存我的 Email
。但是,当我打开保存的 .eml
和 .mht
格式时,它是格式为 <tags>
.
有没有办法将 email.Body
的原始 HTML
格式保存为原始外观?
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.");
}
else
{
Console.WriteLine("Exiting Program without saving file.");
}
}
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
}
您实际上是在从几个属性中重新组合消息。为什么不获取整个 MIME 消息(包括所有 headers、附件等)?