我正在制作一个可以发送电子邮件和阅读电子邮件的小程序。我目前可以发送电子邮件,但我不确定如何使用 .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);
}
最佳答案
您无法使用 SMTP 接收电子邮件。你需要使用 IMAP
考虑使用类似 https://github.com/andyedinborough/aenetmail 的库电子邮箱
有关更多信息,请访问此处: Accessing Imap in C#
https://stackoverflow.com/questions/41835707/
相关文章:
reactjs - 如何在常规 HTML 页面中引用 React 组件
excel - 如何根据时间应用 WorksheetFunction.CountIfs?
javascript - 在javascript中将对象作为参数传递的性能
wordpress - 如何禁用 Wordpress/Woocommerce 中的自动 https
python-3.x - 无法将音频上传到 Telegram 错误请求 : failed to ge
amazon-dynamodb - DynamoDB PutItem 然后 UpdateItem 与