VS.NET 2010 (and above) Users Click Here   

HOMECONTACT PRODUCTS DOWNLOADS PURCHASE TESTIMONIALS FORUMS COMPANY CONTACT
Home
Products
Downloads
Purchase
Licensing
Licensing FAQ
Software Updates
Support Forums
Testimonials
Feature Requests
Guarantee
About Us
Contact Us
Hosting Companies
Privacy Policy
   
Shopping Cart



Using ListNanny to Extract MBX (MBox) Files

by Dave 26. March 2011 06:34

One of the capabilities of ListNanny, is for it to be able to parse MBX (sometimes called MBox or Mailbox) files. It can parse and classify individual bounces found within those files.

However, another use, is to simply use ListNanny to convert the MBX file into it's individual emails.

Here is a short, but complete code example on how to do this.


[C#]

//counter used for naming individual files
private int mbxCounter = 0;
private void ExtractMBX()
{

	//mbx path (change to match your system)
	string mbxPath  = @"D:\temp\main.mbx";

	//processing engine found in ListNanny
	ProcessingEngine pe = new ProcessingEngine();

	//wire up the OnBeforeParse file event
	pe.BeforeParseFile += new BeforeParseFileEventHandler( OnBeforeFileParse );
	pe.ProcessMBXFile( mbxPath );

}

private void OnBeforeFileParse( object sender, BeforeParseFileEventArgs e )
{
	//in this event, we will extract the email, save it to a file

	//email file path
	string emailFile  = @"d:\temp\MBXFiles\ExractedFile" + mbxCounter.ToString("00000") + ".eml";

	//write out the file
	string contents = e.Contents;
	StreamWriter sw = new StreamWriter(emailFile);
	sw.Write( contents );
	sw.Flush();

	//tell ListNanny to ignore any further processing
	e.IgnoreFile = true;
	e.Contents = string.Empty;
	
	mbxCounter++;
}



[VB.NET]

 'counter used for naming individual files
Private mbxCounter As Integer = 0

Private Sub ExtractMBX()
   
   'mbx path (change to match your system)
   Dim mbxPath As String = "D:\temp\main.mbx"
   
   'processing engine found in ListNanny
   Dim pe As New ProcessingEngine()
   
   'wire up the OnBeforeParse file event
   AddHandler pe.BeforeParseFile, AddressOf OnBeforeFileParse
   pe.ProcessMBXFile(mbxPath)
End Sub 'ExtractMBX
 

Private Sub OnBeforeFileParse(sender As Object, e As BeforeParseFileEventArgs)
   'in this event, we will extract the email, save it to a file
   'email file path
   Dim emailFile As String = "d:\temp\MBXFiles\ExractedFile" + mbxCounter.ToString("00000") + ".eml"
   
   'write out the file
   Dim contents As String = e.Contents
   Dim sw As New StreamWriter(emailFile)
   sw.Write(contents)
   sw.Flush()
   
   'tell ListNanny to ignore any further processing
   e.IgnoreFile = True
   e.Contents = String.Empty

   mbxCounter += 1
End Sub 

As always, if anyone has any questions, let me know through the Contact Us page. Thanks! Dave

Comments are closed

 

 

Testimonial

Last year I bought components from both you and from [xxx]. [xxx]'s support is horrendous, to say the least (you have to hate it when you, as a customer, clearly know more about the product than their support personnel). Good work on your frighteningly prompt support. "

Fraser T.

Read more testimonials
ListNanny aspNetDNS aspNetEmail aspNetPOP3 aspNetMX IPMuncher aspNetMIME aspNetPING aspNetTraceRoute aspNetIMAP aspNetMHT