我正在製作一個可發送電子郵件和閱讀電子郵件的小程序。我目前可以發送電子郵件,但是我不確定如何使用.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。 –