我使用免费的.net库来阅读电子邮件,我发布:如果我想查看正文消息,所有免费的.net电子邮件库下载正文消息和附件。如果附件尺寸很大,我会等很长时间。示例:我使用AE.NET.Mail阅读最新的电子邮件:
var dt = DateTime.Now;
Console.WriteLine(dt.ToLongTimeString());
// Connect to the IMAP server. The 'true' parameter specifies to use SSL
// which is important (for Gmail at least)
var ic = new ImapClient("imap.gmail.com", "yourEmail", "yourPassword",
ImapClient.AuthMethods.Login, 993, true);
// Select a mailbox. Case-insensitive
var mailCount = ic.GetMessageCount();
ic.SelectMailbox("INBOX");
var message = ic.GetMessage(mailCount - 1);
var body = message.Body;
Console.WriteLine(body);
ic.Disconnect();
ic.Dispose();
Console.WriteLine(DateTime.Now.ToLongTimeString());
Console.WriteLine((DateTime.Now - dt).TotalSeconds);
结果:478,6s,附件大小23mb。 如果我只想以最快的速度查看正文消息,我该怎么办?
答案 0 :(得分:0)
我正在给你链接,请关注它并尝试另一个开源邮件库它可以帮助你消耗更少的时间。 TRY THIS然后将代码如下所示
MailRepository rep = new MailRepository("imap.gmail.com", 993, true, @"username", "password");
foreach (ActiveUp.Net.Mail.Message email in rep.GetUnreadMails("Inbox"))
{
System.Web.HttpContext.Current.Response.Write(string.Format("<p>{0}: {1}</p><p>{2}</p>", email.From, email.Subject, email.BodyHtml.Text));
}