Referencing Headers Part I
The following example demonstrates referencing various headers of an email message. One important item to note, is that the headers must be checked if they are null, before referencing any of their properties.


[C#]

//create a new pop3 object POP3 pop = new POP3("127.0.0.1","dave@blah.com", "mypassword" ); //connect to the POP3 server pop.Connect(); //retrieve the first MimeMessage MimeMessage msg = pop.GetMessage(0); //Close the POP3 Connection pop.Disconnect(); //write out some of the headers if( msg.Subject != null ) Console.WriteLine( msg.Subject.Value ); if( msg.To != null ) msg.To.ToString(); if( msg.From != null ) Console.WriteLine( msg.From.EmailAddress ); if( msg.ContentType != null ) Console.WriteLine( msg.ContentType.Value ); //reference an X-Header if( msg.Headers[ "X-Mailer" ] != null ) Console.WriteLine( msg.Headers[ "X-Mailer" ].Value ); //done Console.WriteLine( "done."); Console.ReadLine( );


[VB.NET]

'create a new pop3 object Dim pop As New POP3("127.0.0.1", "dave@blah.com", "mypassword") 'connect to the POP3 server pop.Connect() 'retrieve the first MimeMessage Dim msg As MimeMessage = pop.GetMessage(0) 'Close the POP3 Connection pop.Disconnect() 'write out some of the headers If Not (msg.Subject Is Nothing) Then Console.WriteLine(msg.Subject.Value) End If If Not (msg.To Is Nothing) Then msg.To.ToString() End If If Not (msg.From Is Nothing) Then Console.WriteLine(msg.From.EmailAddress) End If If Not (msg.ContentType Is Nothing) Then Console.WriteLine(msg.ContentType.Value) End If 'reference an X-Header If Not (msg.Headers("X-Mailer") Is Nothing) Then Console.WriteLine(msg.Headers("X-Mailer").Value) End If 'done Console.WriteLine("done.") Console.ReadLine()