[英]How to read mail content through c# console application
MailRepository rep = new MailRepository("imap.mail.yahoo.com", 993, true, @"xxxxx@yahoo.com", "*******");
foreach (Message email in rep.GetUnreadMails("Inbox"))
{
//Console.WriteLine(string.Format("<p>{0}: {1}</p><p>{2}</p>", email.From, email.Subject, email.BodyHtml.Text));
Console.WriteLine(email.From);
Console.WriteLine(email.Subject);
Console.WriteLine(email.BodyHtml.Text);
if (email.Attachments.Count > 0)
{
foreach (MimePart attachment in email.Attachments)
{
Console.WriteLine(string.Format("<p>Attachment: {0} {1}</p>", attachment.ContentName, attachment.ContentType.MimeType));
}
}
}
Above is my code, which is used to read mail content. 上面是我的代码,用于读取邮件内容。 It's working fine when i tryed for gmail port, but while going for yahoo or some other.
当我尝试使用gmail端口时,它工作正常,但是在使用yahoo或其他工具时。 It's not allowing me to read the mail throwing exception.
它不允许我阅读邮件引发异常。 Is there any other source .
还有其他来源吗? Please guide me
请指导我
First , check your credentials are correct. 首先 ,检查您的凭据是否正确。
Second , put a try catch in the constructor to see if you can get more info about the unhandled exception: 其次 ,将try catch放入构造函数中,以查看是否可以获得有关未处理异常的更多信息:
public MailRepository(string mailServer, int port, bool ssl, string login, string password)
{
try {
if (ssl) {
Client.ConnectSsl(mailServer, port);
}
else {
Client.Connect(mailServer, port);
}
Client.Login(login, password);
}
catch(Exception ex)
{
//Check the exception details here
}
}
Third , the origin of the MailRepository
class appears to be from here that uses the Imap4Client
implementation which others have complained doesn't work with Yahoo: Connecting to yahoo email with IMAP4 MailSystem.NET 第三 ,
MailRepository
类的来源似乎是从这里开始的 ,它使用了其他人抱怨的不适用于Yahoo的Imap4Client
实现: 使用IMAP4 MailSystem.NET连接到yahoo电子邮件
The accepted answer recommends using ImapX 2 - crossplatform IMAP library for .NET to handle GMail, Yahoo, etc. 接受的答案建议使用ImapX 2-用于.NET的跨平台IMAP库来处理GMail,Yahoo等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.