PowerTCP Mail for .NET
Getting All Message Headers
Send comments on this topic.



Glossary Item Box

It is often useful to retrieve only the headers of a message. This enables the mail client to quickly display data about all messages in the mail drop without having to actually download each message, as doing so often can be time consuming, especially when dealing with large attachments.

To get all message headers, follow these steps.

  1. Add the Pop component to a new form.
  2. Import the namespace of the component you would like to use using "Using" (C#) or "Imports" (VB.NET). Place the following code at the top of your file.
    C# Copy Code
    using Dart.PowerTCP.Mail;
    Visual Basic Copy Code
    Imports Dart.PowerTCP.Mail
  3. Add a Button and a ListView to the form.
  4. Set the properties required to properly get all message headers from the server. Place the following code in the Click event of the button added to the form in step 3.
    C# Copy Code
    // Be sure the Pop component is configured to automatically retrieve message headers.
    pop1.AutoGet = MessageSection.Header;
    Visual Basic Copy Code
    ' Be sure the Pop component is configured to automatically retrieve message headers.
    Pop1.AutoGet = Header
  5. Login to the server. All message headers will be automatically retrieved. Place this code directly after the code from step 5.
    C# Copy Code
    // Login to the POP server.
    pop1.Login("mail.myserver.com", "test", "pass");
    Visual Basic Copy Code
    ' Login to the POP server.
    Pop1.Login("mail.myserver.com", "test", "pass")
  6. At this point all message headers are retrieved. Prepare the ListView for display.
    C# Copy Code
    // Set up ListView to display some values
    listView1.GridLines = true;
    listView1.View = View.Details;
    
    // Add some column headers to ListView
    listView1.Columns.Add("From", 100, HorizontalAlignment.Left);
    listView1.Columns.Add("Subject", 100, HorizontalAlignment.Left);
    Visual Basic Copy Code
    ' Set up ListView to display some values
    ListView1.GridLines = True
    ListView1.View = View.Details
    
    ' Add some column headers to ListView
    ListView1.Columns.Add("From", 100, HorizontalAlignment.Left)
    ListView1.Columns.Add("Subject", 100, HorizontalAlignment.Left)
  7. Iterate through the PopMessages retrieved from the server and display the data in the ListView.
    C# Copy Code
    // Iterate through the messages and add the appropriate data to the ListView
    foreach(PopMessage msg in pop1.Messages)
    {
       string[] items = {msg.Message.From.Address, msg.Message.Subject};
       listView1.Items.Add(new ListViewItem(items));
    }
    Visual Basic Copy Code
    ' Iterate through the messages and add the appropriate data to the ListView
    Dim msg As PopMessage
    For Each msg In Pop1.Messages
       Dim items() As String = {msg.Message.From.Address, msg.Message.Subject}
       ListView1.Items.Add(New ListViewItem(items))
    Next
  8. This application could be extended to allow the user to select a message from the ListView, at which point the selected message would be downloaded and displayed.
Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.