【问题标题】:Receiving Server Not Found Error using POP3 for downloading e-mails from Outlook使用 POP3 从 Outlook 下载电子邮件时未找到接收服务器错误
【发布时间】:2015-06-15 04:24:57
【问题描述】:

使用 POP3 我想从 Outlook 下载邮件,但我无法连接服务器。它在连接到服务器时显示。 错误是:

在 OpenPop.Pop3.Pop3Client.Connect 上找不到服务器(字符串 主机名、Int32 端口、布尔值 useSsl、Int32 接收超时、Int32 sendTimeout, RemoteCertificateValidationCallback certificateValidator) 在 Aceo.Activities.EmailPOP.RequestEmailPOP.Execute(CodeActivityContext 上下文)

在参数中,我通过:

Host number="mail.xxx.com"

Use SSl=false or true

Port Number= 110 or 995

我的代码是:

public sealed class RequestEmailPOP:CodeActivity
{
    public InArgument<string> Host { get; set; }
    public InArgument<string> PortNumber { get; set; }
    public InArgument<string> UseSSL { get; set; }
    public InArgument<string> UserName { get; set; }
    public InArgument<string> Password { get; set; }
    public InArgument<string> LoggedInUser { get; set; }

    protected override void Execute(CodeActivityContext context)
    {

            string Host = context.GetValue(this.Host);
            int PortNumber =Convert.ToInt32(context.GetValue(this.PortNumber));
            bool UseSSL = Convert.ToBoolean(context.GetValue(this.UseSSL));
            string UserName = context.GetValue(this.UserName);
            string LoggedInUser = context.GetValue(this.LoggedInUser);
            string Password = context.GetValue(this.Password);
            using (Pop3Client client = new Pop3Client())
            {
                client.Connect(Host, PortNumber, UseSSL, 600, 600, CertificateValidationCallBack);
                client.Authenticate(UserName, Password);
                int messageCount = client.GetMessageCount();
                List<string> uids = client.GetMessageUids();
                List<Message> newMessages = new List<Message>();
                for (int i = 0; i < uids.Count; i++)
                {
                    string currentUidOnServer = uids[i];
                    if (!seenUids.Contains(currentUidOnServer))
                    {
                        Message unseenMessage = client.GetMessage(i + 1);
                        newMessages.Add(unseenMessage);
                    }
                }
           }
            return newMessage;
     } 

   private static bool CertificateValidationCallBack(
           object sender,
           System.Security.Cryptography.X509Certificates.X509Certificate certificate,
           System.Security.Cryptography.X509Certificates.X509Chain chain,
           System.Net.Security.SslPolicyErrors sslPolicyErrors)
          {
                  return true;
          }       

如何解决此错误?

【问题讨论】:

    标签: c# asp.net-mvc ssl pop3


    【解决方案1】:

    您现在可能已经弄清楚了,但问题可能是由于您传递给Connect() 方法的超时值极低(600 毫秒)。这是一个非常低的超时值,并且可能没有足够的时间让套接字连接到远程主机。

    现在插入我自己的 OpenPOP.NET 替代方案 :-)

    许多开发人员使用超时作为“网络挂起”的解决方案,而更好的解决方案是有办法取消操作。

    MailKit 是唯一允许这样做的邮件库。每个需要网络活动的 API 都有一个可选的 CancellationToken 参数,该参数为 API 的使用者提供了根据需要取消该操作的权力。

    与依赖几乎永远不会按预期工作的任意超时相比,这是一个更好的解决方案。

    (注意:MailKit 也允许设置超时,但我非常不鼓励使用它们,因为它们几乎总是被错误地使用)。

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-06
      • 1970-01-01
      • 1970-01-01
      • 2017-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多