The POP specification defines a "TOP" command, which can be used to get a specified number of lines of a message. This can be accomplished by using the Get method.
To perform a "TOP" on a message, use the following 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 to the form.
- Be sure to set the Pop component to NOT automatically retrieve all messages after login. 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 not get any messages upon login. pop1.AutoGet = MessageSection.None; // Must stay logged in so the code which follows will work pop1.AutoLogout = false;
Visual Basic
Copy Code' Be sure the Pop component is configured to not get any messages upon login. Pop1.AutoGet = None ' Must stay logged in so the code which follows will work Pop1.AutoLogout = False
- Login to the server. 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")
- After login, a collection of PopMessage objects is created, representing the messages on the server. Since Pop.AutoGet = MessageSection.None, these objects do not contain any actual message data, but simply contain the information returned by the POP server (ID and size). To perform a top, you simply call the Get method of the PopMessage object representing the message you would like to get, passing in the amount of lines you would like to get. Get 10 lines from the first message.
C#
Copy Code// Get the first 10 lines of the message. pop1.Messages[0].Get(10);Visual Basic
Copy Code' Get the first 10 lines of the message. Pop1.Messages(0).Get(10) - Upon success, this PopMessage object should contain the message data for the first 10 lines of the message. You can now use this message within your application. Check the message to see if it has text, and if so, display in a TextBox.
C#
Copy Code// Check to see if the message has any text. if(pop1.Messages[0].Message.Text != "") { textBox1.Text = pop1.Messages[0].Message.Text; } else { textBox1.Text = "No displayable text."; }
Visual Basic
Copy Code' Check to see if the message has any text. If Pop1.Messages(0).Message.Text <> "" Then TextBox1.Text = Pop1.Messages(0).Message.Text Else TextBox1.Text = "No displayable text." End If
- Because Pop.AutoLogout = false, the Pop component has to be explicitly logged out.
C#
Copy Code// Logout. pop1.Logout();Visual Basic
Copy Code' Logout. Pop1.Logout() - Compile and run the application.