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

时间:2018-11-13 12:16:02

标签: c# imap pop3

我使用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进行检索时,我找不到能检测到检索到的邮件是否被退回的方法

2 个答案:

答案 0 :(得分:0)

对于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();

答案 1 :(得分:0)

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

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