如何使用AE.Net.Mail将gmail收件箱中的每封电子邮件作为eml文件下载 [英] how to download each email in gmail inbox as eml file using AE.Net.Mail

查看:122
本文介绍了如何使用AE.Net.Mail将gmail收件箱中的每封电子邮件作为eml文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

foreach(MailMessage cm in mm)

{

Console.WriteLine(消息号+ i ++ cm.From);

string curpath = Directory.GetCurrentDirectory();

string mailbox = String.Format({0} \\\\ box,curpath);



如果(!Directory.Exists(邮箱))

{

Directory.CreateDirectory(邮箱);

}

System.DateTime d = System.DateTime.Now;

System.Globalization.CultureInfo cur = new

System.Globalization.CultureInfo (en-US);

string sdate = d.ToString(MMyyyyddHHmmss,cur);

string fileName1 = String.Format({0} \\ \\\ {1} {2} {3} .eml,mailbox,sdate,d.Millisecond.ToString(d3),i); // mailbox,sdate,d.Millisecond.ToString(d3),i,

StreamWriter sw = new StreamWriter(fileName1);

cm.Save(sw) ;

i ++

}





这里创建了eml文件但是当用雷鸟打开时,附件显示为文本。有人帮助我以正确的格式将附件保存在eml中。谢谢。

foreach (MailMessage cm in mm)
{
Console.WriteLine("Message No." + i + " " + cm.From);
string curpath = Directory.GetCurrentDirectory();
string mailbox = String.Format("{0}\\inbox", curpath);

if (!Directory.Exists(mailbox))
{
Directory.CreateDirectory(mailbox);
}
System.DateTime d = System.DateTime.Now;
System.Globalization.CultureInfo cur = new
System.Globalization.CultureInfo("en-US");
string sdate = d.ToString("MMyyyyddHHmmss", cur);
string fileName1 = String.Format("{0}\\{1}{2}{3}.eml", mailbox, sdate, d.Millisecond.ToString("d3"), i); //mailbox, sdate, d.Millisecond.ToString("d3"), i,
StreamWriter sw = new StreamWriter(fileName1);
cm.Save(sw);
i++
}


Here the eml file is been created but the attachments are shown as text when opened with thunderbird. Somebody help me to get the attachment too saved in eml in correct formats. Thanks.

推荐答案

考虑到没有电子邮件服务器会向您发送电子邮件作为文件,您的问题实际上没有任何意义。



你必须像任何IMAP或SMTP客户端那样下载电子邮件,然后自己获取该信息并构建一个EML文件。



代码你没有建立一个真正的EML文件。您必须获取MailMessage对象中的信息并自行编写RFC 822文件格式。您可以阅读此处的格式[ ^ ]。
Considering no email server will send you an email as a file your question doesn't really make any sense.

You have to download the email as any IMAP or SMTP client would and then take that information and build an EML file yourself.

The code you have doesn't build a real EML file. You have to take the information in the MailMessage object and write the RFC 822 file format yourself. You can read up on the format here[^].


这篇关于如何使用AE.Net.Mail将gmail收件箱中的每封电子邮件作为eml文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆