0

我使用免费的 .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。如果我只想以最快的速度查看正文消息怎么办?

4

1 回答 1

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));


    }
于 2012-09-07T05:36:21.537 回答