获取收件箱中的所有电子邮件.Net.Mail C#

时间:2017-01-24 17:53:02

标签: c# email system.net.mail

我制作了一个可以发送电子邮件和阅读电子邮件的小程序。我目前可以发送电子邮件,但我不确定如何使用.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);
}

2 个答案:

答案 0 :(得分:0)

您无法通过SMTP收到电子邮件。您需要使用IMAP

考虑使用像https://github.com/andyedinborough/aenetmail AEMail

这样的库

欲了解更多信息,请点击此处: Accessing Imap in C#

答案 1 :(得分:-3)

尝试类OpenPop

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

它有文档

相关问题