Provides data for the
Processed Event.
Shows how to handle the Processed, Processing, and Progress events when processing messages.
using System;
using System.Windows.Forms;
using ComponentPro.Net.Mail;
...
static void Main()
{
try
{
// Create a new instance of the BounceInspector class.
BounceInspector inspector = new BounceInspector();
// Register the event handler to the Processed event.
inspector.Processed += inspector_Processed;
// and Processing event.
inspector.Processing += inspector_Processing;
// Register the event handler to the Progress event.
inspector.Progress += inspector_Progress;
// Process all EML files in directory 'c:\\temp'.
BounceResultCollection result = inspector.ProcessMessages("c:\\temp");
Console.WriteLine("{0} bounced message found", result.BounceCount);
}
catch (Exception exc)
{
MessageBox.Show(string.Format("An error occurred: {0}", exc.Message));
}
}
/// <summary>
/// Handles the BounceInspector's Processing event.
/// </summary>
/// <param name="sender">The BounceInspector object.</param>
/// <param name="e">The event arguments.</param>
static void inspector_Processing(object sender, ProcessingEventArgs e)
{
Console.WriteLine("Processing message {0}", e.Filename);
// Skip some files.
if (e.Filename.IndexOf("test.eml") != -1)
e.Skip = true;
}
/// <summary>
/// Handles the BounceInspector's Processed event.
/// </summary>
/// <param name="sender">The BounceInspector object.</param>
/// <param name="e">The event arguments.</param>
static void inspector_Processed(object sender, ProcessedEventArgs e)
{
BounceResult r = e.Result;
// If this message was identified as a bounced email message and the message object is not null.
if (r.Identified && r.MailMessage != null)
{
// 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);
}
}
/// <summary>
/// Handles the BounceInspector's Progress event.
/// </summary>
/// <param name="sender">The BounceInspector object.</param>
/// <param name="e">The event arguments.</param>
static void inspector_Progress(object sender, ProgressEventArgs e)
{
Console.WriteLine("{0}/{1} message(s) processed", e.Current, e.Total);
}
Imports ComponentPro.Net.Mail
...
Shared Sub Main()
Try
' Create a new instance of the BounceInspector class.
Dim inspector As New BounceInspector()
' Register the event handler to the Processed event.
AddHandler inspector.Processed, AddressOf inspector_Processed
' and Processing event.
AddHandler inspector.Processing, AddressOf inspector_Processing
' Register the event handler to the Progress event.
AddHandler inspector.Progress, AddressOf inspector_Progress
' Process all EML files in directory 'c:\\temp'.
Dim result As BounceResultCollection = inspector.ProcessMessages("c:\temp")
Console.WriteLine("{0} bounced message found", result.BounceCount)
Catch exc As Exception
MessageBox.Show(String.Format("An error occurred: {0}", exc.Message))
End Try
End Sub
''' <summary>
''' Handles the BounceInspector's Processing event.
''' </summary>
''' <param name="sender">The BounceInspector object.</param>
''' <param name="e">The event arguments.</param>
Private Shared Sub inspector_Processing(ByVal sender As Object, ByVal e As ProcessingEventArgs)
Console.WriteLine("Processing message {0}", e.Filename)
' Skip some files.
If e.Filename.IndexOf("test.eml") <> -1 Then
e.Skip = True
End If
End Sub
''' <summary>
''' Handles the BounceInspector's Processed event.
''' </summary>
''' <param name="sender">The BounceInspector object.</param>
''' <param name="e">The event arguments.</param>
Private Shared Sub inspector_Processed(ByVal sender As Object, ByVal e As ProcessedEventArgs)
Dim r As BounceResult = e.Result
' If this message was identified as a bounced email message and the message object is not null.
If r.Identified AndAlso r.MailMessage IsNot Nothing Then
' Print out the result
Console.Write("FileName: {0}" & vbLf & "Subject: {1}" & vbLf & "Address: {2}" & vbLf & "Bounce Category: {3}" & vbLf & "Bounce Type: {4}" & vbLf & "Deleted: {5}" & vbLf & "DSN Action: {6}" & vbLf & "DSN Diagnostic Code: {7}" & vbLf & vbLf, 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)
End If
End Sub
''' <summary>
''' Handles the BounceInspector's Progress event.
''' </summary>
''' <param name="sender">The BounceInspector object.</param>
''' <param name="e">The event arguments.</param>
Private Shared Sub inspector_Progress(ByVal sender As Object, ByVal e As ProgressEventArgs)
Console.WriteLine("{0}/{1} message(s) processed", e.Current, e.Total)
End Sub
ComponentPro.Net.Mail.ComponentPro.Net.Mail.ProcessedEventArgs