2017-01-24 84 views
0

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

我的代码休耕

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

    // set smtp-client with basicAuthentication 
    mySmtpClient.UseDefaultCredentials = false; 
    System.Net.NetworkCredential basicAuthenticationInfo = new 
     System.Net.NetworkCredential("[email protected]", "password"); 
    mySmtpClient.Credentials = basicAuthenticationInfo; 
    mySmtpClient.EnableSsl = true; 

    // add from,to mailaddresses 
    MailAddress from = new MailAddress("[email protected]"); 
    MailAddress to = new MailAddress("[email protected]"); 
    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

如果要访问Microsoft邮件帐户的存储电子邮件文件夹,请考虑REST API @ https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations - POP不会削减它。 –

+0

这对于框架的System.Net.Mail是不可能的。您需要一个类似[MailKit](https://github.com/jstedfast/MailKit)的图书馆,支持IMAP或POP3。 –

回答

0

你不能收到电子邮件,其中SMTP。您需要使用IMAP

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

欲了解更多信息请点击这里: Accessing Imap in C#

+1

或者还有POP3 –

+0

@PeterRitchie - 是的,但谁想要使用它? –

+0

@ rory.ap通常不是关于某些邮件提供商的选择:( –

-3

尝试类OpenPop

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

这是有文件

+1

这应该是一个问题下的评论。 –

相关问题