[Предупреждение] ошибка слишком большого количества одновременных подключений при использовании mailsystem.net с помощью gmail
I'm trying to use the MailSystem.Net to retrieve mails from my gmail account but i get the above error. I have just follow through an example online to make a demo application as a window service. I tried to log the errors to a folder and after running the service i get the above error repeatedly in my error error folder
What I have tried:
<pre lang="c#">public class MailRepository
{
private Imap4Client client;
public MailRepository(string mailServer, int port, bool ssl, string login, string password)
{
if (ssl)
Client.ConnectSsl(mailServer, port);
else
Client.Connect(mailServer, port);
Client.Login(login, password);
}
public IEnumerable<Message> GetAllMails(string mailBox)
{
return GetMails(mailBox, "ALL").Cast<Message>();
}
public IEnumerable<Message> GetUnreadMails(string mailBox)
{
return GetMails(mailBox, "UNSEEN").Cast<Message>();
}
protected Imap4Client Client
{
get { return client ?? (client = new Imap4Client()); }
}
private MessageCollection GetMails(string mailBox, string searchPhrase)
{
Mailbox mails = Client.SelectMailbox(mailBox);
MessageCollection messages = mails.SearchParse(searchPhrase);
return messages;
}
}
private void ReadImap()
{
var mailRespository = new MailUtil.MailRepository("imap.gmail.com", 993, true, "myGmailAccount", "Mypassword");
var emailList = mailRespository.GetAllMails("inbox");
foreach(Message email in emailList)
{
//DoSomething
if(email.Attachments.Count > 0)
{
//DoSomething
}
}
}