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.
- Add the Pop component to a new form.
- 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 Codeusing Dart.PowerTCP.Mail;Visual Basic
Copy CodeImports Dart.PowerTCP.Mail - Add a Button and a ListView to the form.
- 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 - 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")
- 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)
- 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
- 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.