Access Mime Headers

The following example demonstrates accessing different headers of the aspNetMime MimeMessage.


[C#]

//an email on the filesystem
string filename = "testEmail.eml";

//this creates a MimeMessage from a stream
aspNetMime.MimeMessage msg = aspNetMime.MimeMessage.ParseFile( filename );

//access different headers
Header h = msg.GetHeader( "Status" );

//check for a status header
if( h != null )
	Console.WriteLine( h.RawValue );

//check for a X-header "X-Organization"
h = msg.GetXHeader( "Organization "); //the GetXHeader() method will find headers that start with X-
if( h!= null )
	Console.WriteLine( h.RawValue );

//check for X-OriginalArrivalTime
h = msg.GetXHeader( "OriginalArrivalTime" );
if( h != null )
	Console.WriteLine( h.RawValue );

Console.WriteLine( "done..." );
Console.ReadLine();

 

[VB.NET]

'an email on the filesystem
Dim filename As String =  "testEmail.eml" 
  
'this creates a MimeMessage from a stream
Dim msg As aspNetMime.MimeMessage =  aspNetMime.MimeMessage.ParseFile( filename ) 
 
'access different headers
Dim h As Header =  msg.GetHeader("Status") 
 
'check for a status header
If Not h Is Nothing Then
	Console.WriteLine(h.RawValue)
End If
 
'check for a X-header "X-Organization"
h = msg.GetXHeader("Organization ") 'the GetXHeader() method will find headers that start with X-
If Not h Is Nothing Then
	Console.WriteLine(h.RawValue)
End If
 
'check for X-OriginalArrivalTime
h = msg.GetXHeader("OriginalArrivalTime")
If Not h Is Nothing Then
	Console.WriteLine(h.RawValue)
End If
 
Console.WriteLine("done...")
Console.ReadLine()