Limilabs IMAP例外

时间:2014-10-19 16:58:20

标签: imap

我正在尝试使用Limilabs imap库连接到电子邮件;

  tcpc = new System.Net.Sockets.TcpClient("imap.gmail.com", 993);

工作正常;虽然limilabs imap没有

using (Imap imap = new Imap())
{
    imap.Connect("imap.gmail.com", 993);

给出例外:

Limilabs.Client.ServerException was unhandled
  HResult=-2146233088
  Message=Tried to read a line. No data received. Please make sure that antivirus and firewall software are disabled or configured correctly.
  Source=Mail
  StackTrace:
       at   .()
       at   .(MemoryStream )
       at   .()
       at Limilabs.Client.IMAP.ImapResponse.(Stream )
       at Limilabs.Client.IMAP.Imap.(ImapResponse )
       at Limilabs.Client.IMAP.Imap.(String , Boolean )
       at Limilabs.Client.IMAP.Imap.ReceiveResponse(String tag)
       at Limilabs.Client.IMAP.Imap.wqf45mzzsju7786nbrb2h8aclqm8jmnx    ()
       at Limilabs.Client.ClientBase.Connect(String host, Int32 port, Boolean useSSL)
       at Limilabs.Client.ClientBase.Connect(String host, Int32 port)
       at ConsoleIMAP.Program.Main(String[] args) in c:\users\hmohamed\WcfServiceLibrary1\ConsoleIMP\Program.cs:line 136
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2146233088
       Message=Tried to read a line. No data received.
       Source=Mail
       StackTrace:
            at   .()
       InnerException: 

2 个答案:

答案 0 :(得分:2)

Limilabs imap.Connect有一个重载来指定是否使用SSL。它不会从您指定的端口推断它。您也可以使用imap.ConnectSSL方法。

有关详细信息,请参阅: http://www.limilabs.com/blog/use-ssl-with-imap

答案 1 :(得分:1)

我知道这个问题是2岁,但对于遇到此问题的其他人来说可能很重要。

Imap.Connect / Imap.ConnectSSL方法不仅可以连接,还可以启动TLS / SSL协商(如果需要),接收初始服务器响应,并获得IMAP服务器支持的扩展。

这就是为什么连接TcpClient可能看起来像是在开始工作,但事实上,你还没有启动TLS / SSL协商,也没有与服务器进行任何其他通信。

Gmail仅支持TLS / SSL连接,因此您必须使用ConnectSSL方法,也无需明确指定端口:

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");

    //...

    imap.Close()
}

请记住,您必须enable IMAP access for your account in Gmail