question:
How to read emails using C#?
background:
Answer:
A reliable solution is to use the OpenPop.NET library. Here is how to use it:
Install-Package OpenPop.NET
]
using OpenPop.Pop3;
...
Pop3Client client = new Pop3Client();
client.Connect("pop.example.com", 110, false); // 使用SSL进行安全连接
client.Authenticate("用户名", "密码");
IList messages = client.GetMessages();
foreach (Pop3Message message in messages)
{
// 获取邮件头信息
Console.WriteLine("主题: {0}", message.Headers.Subject);
// 获取邮件正文(包括附件)
message.Load();
Console.WriteLine("正文: {0}", message.MessagePart.BodyAsText);
// 将邮件保存到本地文件
message.SaveToFile("email.txt");
}
client.Dispose();
]
Note: In order to support Unicode, please make sure your system supports UTF-8 encoding.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3