Download Messages' Headers into a DataTable
The following example demonstrates downloading messages 3 - 5 as a DataTable. It then binds the DataTable to a DataGrid to be displayed in an ASP.NET Web Page.

The DataTable contains the following columns:

Int32 MessageNumber -- The message number as found at the POP3 server.

  1. String Headers -- All of the headers

  2. String FromName -- The 'Name' part of the FROM header

  3. String FromAddress -- the 'Address' part of the FROM header

  4. String To -- The 'To' address header

  5. String CC -- The 'CC' address header

  6. String Subject -- The 'Subject' address header

  7. String Date -- The 'Date' address header

  8. String ContentType -- The 'type/subtype' of the Content-Type header


[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(); //download the headers for messages 3 - 5 (inclusive) DataTable dt = pop.HeaderTable(3, 3); //Close the POP3 Connection pop.Disconnect(); //html encode the cells for( int r=0;r<dt.Rows.Count;r++) { //skip the first col because it's an Int32 for( int c=1;c<dt.Columns.Count;c++) { string cellValue = dt.Rows[r][c].ToString(); dt.Rows[r][c] = "&lt;PRE&gt;" + Server.HtmlEncode( cellValue ) + "&lt;/PRE&gt;"; } } //display the datagrid in ASP.NET page DataGrid dg = new DataGrid(); dg.DataSource = dt; dg.DataBind(); Page.Controls.Add( dg );


[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() 'get the messages 3-5 (includes message 3,4, and 5 ) as a DataTable Dim dtMsg As DataTable = pop.MessageTable(3, 3) 'Close the POP3 Connection pop.Disconnect() 'html encode the cells Dim r As Integer For r = 0 To dtMsg.Rows.Count - 1 'skip the first col because it's an Int32 Dim c As Integer For c = 1 To dtMsg.Columns.Count - 1 Dim cellValue As String = dtMsg.Rows(r)(c).ToString() dtMsg.Rows(r)(c) = "&lt;PRE&gt;" + Server.HtmlEncode(cellValue) + "&lt;/PRE&gt;" Next c Next r 'display the DataTable in a DataGrid in an ASP.NET page Dim dgMsg As New DataGrid() dgMsg.DataSource = dtMsg dgMsg.DataBind() Page.Controls.Add(dgMsg)