【问题标题】:How can I detect if my fetched email is bounced or not如何检测我提取的电子邮件是否被退回
【发布时间】:2019-04-16 06:36:30
【问题描述】:

我使用 IMAP 或 POP3 从服务器获取电子邮件并将获取的电子邮件输入到数据库,但我注意到系统中有很多退回的电子邮件,所以我在 google 上搜索了很多以检查获取的电子邮件以及是否被退回的电子邮件我不会将它输入系统,我找到了库 BounceDetectResult 来检测电子邮件是否被退回,但这个库仅适用于消息类型 MimeMessage,所以它在我使用 IMAP 时很有用,但它不适用于消息类型 OpenPop.Mime.Message所以我在使用 POP3 时无法使用它

 var result= BounceDetectorMail.Detect(message);//message type MimeMessage
        if (result.IsBounce) 
        {
            em.DelivaryFailure = true;
        }

所以我的问题是,当我使用 pop3 检索时,我没有找到方法来检测我检索到的消息是否被退回

【问题讨论】:

    标签: c# imap pop3


    【解决方案1】:

    您提到的MailBounceDetector 库似乎使用我的MimeKit 库来检测邮件是否为退回邮件。

    好消息是您可以使用该库,因为我有一个名为MailKit 的 POP3 库,因此您可以使用它来代替 OpenPOP。网。

    【讨论】:

      【解决方案2】:

      对于任何可能需要的人,来自Bounce inspector software library,支持 POP3 和 IMAP:

      // POP3 server information.
      const string serverName = "myserver";
      const string user = "name@domain.com";
      const string password = "mytestpassword";
      const int port = 995;
      const SecurityMode securityMode = SecurityMode.Implicit;
      // Create a new instance of the Pop3Client class.
      Pop3Client client = new Pop3Client();
      Console.WriteLine("Connecting Pop3 server: {0}:{1}...", serverName, port);
      // Connect to the server.
      client.Connect(serverName, port, securityMode);
      // Login to the server.
      Console.WriteLine("Logging in as {0}...", user);
      client.Authenticate(user, password);
      // Initialize BounceInspector.
      BounceInspector inspector = new BounceInspector();
      inspector.AllowInboxDelete = false; // true if you want BounceInspector automatically delete all hard bounces.
      // Register processed event handler.
      inspector.Processed += inspector_Processed;
      // Download messages from Pop3 Inbox to 'c:\test' and process them.
      BounceResultCollection result = inspector.ProcessMessages(client, "c:\\test");
      // Display processed emails.
      foreach (BounceResult r in result)
      {
         // If this message was identified as a bounced email message.
         if (r.Identified)
         {
             // Print out the result
             Console.Write("FileName: {0}\nSubject: {1}\nAddress: {2}\nBounce Category: {3}\nBounce Type: {4}\nDeleted: {5}\nDSN Action: {6}\nDSN Diagnostic Code: {7}\n\n",
                             System.IO.Path.GetFileName(r.FilePath),
                             r.MailMessage.Subject,
                             r.Addresses[0],
                             r.BounceCategory.Name,
                             r.BounceType.Name,
                             r.FileDeleted,
                             r.Dsn.Action,
                             r.Dsn.DiagnosticCode);
         }
      }
      Console.WriteLine("{0} bounced message found", result.BounceCount);
      // Disconnect.
      Console.WriteLine("Disconnecting...");
      client.Disconnect();
      

      【讨论】:

      • 感谢回复,但是这个库不是免费的
      • 您可以使用免费试用版,看看它是否适合您,然后如果您真的想要,请搜索此类替代品:)
      • 是的,我看到这个库可以满足我的要求,但我已经搜索了其他免费库,但我没有找到任何东西
      猜你喜欢
      • 2020-01-14
      • 2021-04-25
      • 2017-05-08
      • 2013-04-15
      • 2017-03-15
      • 2011-07-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      相关资源
      最近更新 更多