【问题标题】:Get all emails in inbox .Net.Mail C#获取收件箱中的所有电子邮件 .Net.Mail C#
【发布时间】:2017-06-09 16:41:54
【问题描述】:

我正在制作一个可以发送电子邮件和阅读电子邮件的小程序。我目前可以发送电子邮件,但我不确定如何使用 .Net.Mail 访问我的收件箱。有没有办法做到这一点?

我的代码是休闲的

try
{
    SmtpClient mySmtpClient = new SmtpClient("smtp.live.com");

    // set smtp-client with basicAuthentication
    mySmtpClient.UseDefaultCredentials = false;
    System.Net.NetworkCredential basicAuthenticationInfo = new
        System.Net.NetworkCredential("example@live.com", "password");
    mySmtpClient.Credentials = basicAuthenticationInfo;
    mySmtpClient.EnableSsl = true;

    // add from,to mailaddresses
    MailAddress from = new MailAddress("example@live.com");
    MailAddress to = new MailAddress("example@example.eu");
    MailMessage myMail = new System.Net.Mail.MailMessage(from, to);
    MailMessage msg; 

    // set subject and encoding
    myMail.Subject = "Test message";
    myMail.SubjectEncoding = System.Text.Encoding.UTF8;

    // set body-message and encoding
    myMail.Body = "<b>Test Mail</b><br>using <b>HTML</b>.";
    myMail.BodyEncoding = System.Text.Encoding.UTF8;
    // text or html
    myMail.IsBodyHtml = true;

    mySmtpClient.Send(myMail);
}

catch (SmtpException ex)
{
    throw new ApplicationException
        ("SmtpException has occured: " + ex.Message);
}

【问题讨论】:

  • 你测试了吗?有什么问题?
  • 如果您想访问存储的 Microsoft 邮件帐户的电子邮件文件夹,请考虑使用 REST API @msdn.microsoft.com/en-us/office/office365/api/… - POP 不会削减它。
  • 框架的 System.Net.Mail 无法做到这一点。你需要一个像 MailKit 这样支持 IMAP 或 POP3 的库。

标签: c# email system.net.mail


【解决方案1】:

您无法使用 SMTP 接收电子邮件。您需要使用 IMAP

考虑使用像https://github.com/andyedinborough/aenetmailAEMail 这样的库

欲了解更多信息,请访问: Accessing Imap in C#

【讨论】:

  • 或者还有POP3
  • @PeterRitchie -- 是的,但谁愿意再使用它?
  • @rory.ap 通常与某些邮件提供商的选择无关 :(
  • @PeterRitchie 没错,没错,我们应该将所有注意事项告知我们的朋友。
【解决方案2】:

尝试类 OpenPop

[http://hpop.sourceforge.net/][1]

有文档

【讨论】:

  • 这应该是问题下的评论。
猜你喜欢
  • 1970-01-01
  • 2019-10-24
  • 1970-01-01
  • 2010-10-14
  • 2019-02-21
  • 1970-01-01
  • 2013-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多