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.
String Headers -- All of the headers
String FromName -- The 'Name' part of the FROM header
String FromAddress -- the 'Address' part of the FROM header
String To -- The 'To' address header
String CC -- The 'CC' address header
String Subject -- The 'Subject' address header
String Date -- The 'Date' address header
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, 5); //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] = "<pre>" + Server.HtmlEncode( cellValue ) + "</pre>"; } } //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, 5) '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) = "<pre>" + Server.HtmlEncode(cellValue) + "</pre>" 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)
Copyright - Contact: Webmaster Last Updated: Tuesday, January 12, 2021