Home | Contact Us | Download | Support | Purchase | Shopping Cart | Products


Product List
  "A thousand times THANX for all your help!"
R.C.
MarkedsConsult
 
More
Testimonials

Referencing Headers Part II

This example builds on Part I. Except, because of the static (shared) method, Header.EmptyHeader() on the header class, null headers can translated to empty strings. Thus negating the need for checking for nulls.  Compare this example to Referencing Headers Part I.

[C#]

using System;
using aspNetPOP3;
using aspNetMime;
namespace cstest
{
	class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{
			//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 message
			MimeMessage msg = pop.GetMessage(1);

			//Close the POP3 Connection
			pop.Disconnect();

			//write out some of the headers, if they are null, Header.EmptyHeader() 
			returns an empty header, resulting in string.empty for values.
			Console.WriteLine( Header.EmptyHeader(msg.Subject).Value );
			Console.WriteLine( Header.EmptyHeader( msg.ContentType).Value );

			//reference an X-Header
			Console.WriteLine( Header.EmptyHeader( msg.Headers[ "X-Mailer" ]).Value );
            
			//done
			Console.WriteLine( "done.");
			Console.ReadLine( );
            
		}
	}
}


 

[VB.NET]

Imports aspNetPOP3
Imports aspNetMime

Module Module1

    Sub Main()

        '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 message
        Dim msg As MimeMessage = pop.GetMessage(1)

        'Close the POP3 Connection
        pop.Disconnect()

        'write out some of the headers, if they are null, Header.EmptyHeader() returns
         an empty header, resulting in string.empty for values.
        Console.WriteLine(Header.EmptyHeader(msg.Subject).Value)
        Console.WriteLine(Header.EmptyHeader(msg.ContentType).Value)

        'reference an X-Header
        Console.WriteLine(Header.EmptyHeader(msg.Headers("X-Mailer")).Value)

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


    End Sub

End Module

 

 

 

 



The box is not shipped. aspNetPOP3 is a downloadable product.