使用带有gmail的mailsystem.net时,[ALERT]会出现太多同时连接错误 [英] [ALERT] too many simultaneous connections error while using mailsystem.net with gmail
本文介绍了使用带有gmail的mailsystem.net时,[ALERT]会出现太多同时连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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;
}
}
< br $>
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
}
}
}
推荐答案
看起来连接没有关闭(已断开连接)不再使用时。
要知道如何操作,您应该阅读使用过的Imap4Client $ c $的文档c> class。
我希望在Imap4Client
析构函数中关闭连接。但即使这样,最好明确断开连接。
你可以在MailRepository
类中添加一个disconnect方法并在完成使用后调用(从ReadImap
返回时):
It looks like connections are not closed (disconnected) when not used anymore.
To know how to do that you should read the documentation of the usedImap4Client
class.
I would expect that connections are closed in theImap4Client
destructor. But even then it would be better to disconnect explicitly.
You can add a disconnect method to theMailRepository
class and call that when finished using it (when returning fromReadImap
):
public void Disconnect()
{
// Check the Imap4Client documentation for functions doing this
if (Client.isConnected())
Client.Disconnect();
}
但请注意,执行此操作后您无法再查询数据。
But note that you can't query data anymore after doing so.
这篇关于使用带有gmail的mailsystem.net时,[ALERT]会出现太多同时连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文