It is anticipated that the Pop component will be most often used to login to a POP server, get all messages, and logout. However, it may be desirable to only get a single message. A scenario where this could occur is where all message headers are retrieved upon login, fields are displayed to the user (such as "From" and "Subject"), the user selects a message, and the entire message is retrieved.
To get a single 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. Also, be sure that the Pop component will not automatically logout. 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; they simply contain the information returned by the POP server about the message (ID and size). To get a single message, you simply call the Get method of the PopMessage object representing the message you would like to get.
- Get the first message. The message will be encapsulated by a MessageStream object, which will be accessible as the Message property of the PopMessage retrieved. In this case, the message will be accessible at Pop1.Messages[0].Message.
C#
Copy Code// Get a message. pop1.Messages[0].Get();Visual Basic
Copy Code' Get a message. Pop1.Messages(0).Get() - Upon success, the PopMessage.Message property should contain the message data. 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.