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

Product List
  "Being a developer I know that time is money, and you’ve been very helpful with your time and supporting your product, which is more than rare these days, especially with huge impersonal software vendors. I’ve had a lot of bad experiences with terrible customer service lately so it is refreshing that you take the time to help people, not just collect payment pretend the customer doesn’t exist. Thanks Again!"

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:

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

  2. String Headers -- All of the headers

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

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

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

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

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

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

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



            //create a new pop3 object
            POP3 pop = new POP3("","dave@blah.com", "mypassword" );
            //connect to the POP3 server
            //download the headers for messages 3 - 5 (inclusive)
            DataTable dt = pop.HeaderTable(3, 5);
            //Close the POP3 Connection
            //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;
            Page.Controls.Add( dg );



            'create a new pop3 object
            Dim pop As New POP3("", "dave@blah.com", "mypassword")
            'connect to the POP3 server
            '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
            '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




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