The following example illustrates how to use AddBounceSignature to add a custom signature to BounceInspector.
using System; using System.Windows.Forms; using ComponentPro.Net.Mail; ... const int myCategoryCode = 1000; // The category code. const int myTypeCode = 1000; // The type code. try { // Create a new instance of the BounceInspector class. BounceInspector inspector = new BounceInspector(); // Add bounce category "My Category" with code 1000 to the inspector. inspector.AddBounceCategory(myCategoryCode, "My Category"); // Add bounce type "My Type" with code 1000 to the inspector. inspector.AddBounceType(myTypeCode, "My Type"); // Define a custom signature. // Add signature with // regex pattern: '(\S+@\S+\w).*\n?.*my custom signature' // bounce category: 'My Category' // bounce type: 'My Type' // Delete messages: no // analyze this signature first: yes int signatureIndex = inspector.AddBounceSignature(@"(\S+@\S+\w).*\n?.*my custom signature", myCategoryCode, myTypeCode, false, true); // Define a custom signature. // Add signature with // regex pattern: '(\S+@\S+\w).*\n?.*nonexistent(?:\s|\n)domain' // bounce category: DnsUnknown // bounce type: Hard // Delete messages: yes // analyze this signature first: yes inspector.AddBounceSignature(@"(\S+@\S+\w).*\n?.*nonexistent(?:\s|\n)domain", BounceCategory.DnsUnknown, BounceType.Hard, true, true); // Process all EML files in directory 'c:\\temp'. BounceResultCollection result = inspector.ProcessMessages("c:\\temp"); // 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); } } // Modify the added signature to automatically delete all hard bounces. inspector.ModifyBounceSignature(signatureIndex, @"(\S+@\S+\w).*\n?.*my custom signature", myCategoryCode, myTypeCode, true, BounceSignaturePart.Body | BounceSignaturePart.BodyHtml); // Process all EML files in directory 'c:\\temp2'. result = inspector.ProcessMessages("c:\\temp2"); // Process the result here. // ... // Remove the added signature. inspector.RemoveSignature(signatureIndex); // Do something here. // ... Console.WriteLine("{0} bounced message found", result.BounceCount); } catch (Exception exc) { MessageBox.Show(string.Format("An error occurred: {0}", exc.Message)); }