如何检测我提取的电子邮件是否被退回

问题描述 投票:1回答:2

我通过使用IMAP或POP3从服务器获取电子邮件并将获取的电子邮件输入到数据库但我注意到有很多退回的电子邮件输入到系统中所以我在谷歌搜索了很多以检查已获取的电子邮件,如果它被退回电子邮件我会没有输入它到系统,我发现库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
2个回答
0
投票

看起来你提到的MailBounceDetector库使用我的MimeKit库来检测消息是否是退回消息。

好消息是您可以使用该库,因为我还有一个名为MailKit的POP3库,因此您可以使用它而不是OpenPOP.NET。


0
投票

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

// POP3 server information.
const string serverName = "myserver";
const string user = "[email protected]";
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();
© www.soinside.com 2019 - 2024. All rights reserved.