我正在制作一个可发送电子邮件和阅读电子邮件的小程序。我目前可以发送电子邮件,但是我不确定如何使用.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);
}
有你测试过它?什么是问题? –
如果要访问Microsoft邮件帐户的存储电子邮件文件夹,请考虑REST API @ https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations - POP不会削减它。 –
这对于框架的System.Net.Mail是不可能的。您需要一个类似[MailKit](https://github.com/jstedfast/MailKit)的图书馆,支持IMAP或POP3。 –