Getting mail with PowerTCP Mail for .NET is both easy and flexible. A typical scenario would involve logging into a POP server, getting all messages in the mail drop, and logging out.
To quickly and easily get all messages.
- Add the Pop component to a new form. For instructions on how to do this see Placing Components on a Form.
- Import the namespace of the component you would like to use using "Using" (C#) or "Imports" (VB.NET).
[Visual Basic, C#] Place the following code at the top of your file.
[C#]
using Dart.PowerTCP.Mail;
[Visual Basic]
Imports Dart.PowerTCP.Mail
- Add a button to the form.
- Set the properties required to properly get all messages from the server.
[Visual Basic, C#] Place the following code in the Click event of the button added to the form in step 3.
[C#]
// Be sure the Pop component is configured to automatically retrieve messages.
pop1.AutoGet = MessageSection.Complete;
[Visual Basic]
' Be sure the Pop component is configured to automatically retrieve messages.
Pop1.AutoGet = Complete
- Login to the server. All messages will be automatically retrieved. Since Pop.AutoLogout is set to it's default value (true), logout will automatically occur once login has completed.
[Visual Basic, C#] Place this code directly after the code from step 5.
[C#]
// Login to the POP server.
pop1.Login("mail.myserver.com", "test", "pass");
[Visual Basic]
' Login to the POP server.
Pop1.Login("mail.myserver.com", "test", "pass")
- At this point, all messages have been retrieved. Display the number of messages retrieved to the user.
[Visual Basic, C#]
[C#]
Debug.WriteLine(pop1.Messages.Length + " messages retrieved.");
[Visual Basic]
Debug.WriteLine(Pop1.Messages.Length & " messages retrieved.")
- The retrieved messages are represented as PopMessage objects. To access each message, either access an index into the Pop.Messages collection, or access each message using For...Each.
[Visual Basic, C#]
Access message data. For this example, do something trivial like display the number of attachments for each message. [C#]
// Iterate through the messages
foreach(PopMessage msg in pop1.Messages)
{
// Display info about each Message
Debug.Write("Message " + msg.Id);
Debug.Write(" has " + msg.Message.Attachments.Count + " attachments.");
}
[Visual Basic]
Dim Msg As PopMessage
For Each Msg In Pop1.Messages
' Display info about each Message
Debug.Write("Message " + Msg.Id)
Debug.Write(" has " + Msg.Message.Attachments.Count + " attachments.")
Next
In This Section
- Getting All Messages
- Provides a description of the simplest and easiest way to login and get all available mail message.
- Getting All Message Headers
- Provides a description of the simplest and easiest way to login and get all available message headers.
- Getting A Single Message
- Demonstrates how to login in and only get one message.
- Getting Messages Asynchronously
- Demonstrates how asynchronous methods can be used with the Pop component.
- Performing a TOP
- Shows how to get a specified number of lines of a message.
- Decoding Attachments As Files
- Demonstrates how to get messages and decode their attachments as files.
- Decoding Attachments As Streams
- Demonstrates how to get messages and decode their attachments as Streams.
- Displaying Progress While Getting Mail
- Provides a description of how to display progress when getting mail.
- Stream Use When Getting Mail
- Provides a discussion on how Streams are used by the Pop component to make getting mail more flexible.
- Sending Commands To A POP Server
- Shows how to send a command to a POP server and receive the response.
- Making a Trace Log When Getting Mail
- Provides a description of how to create a log file containing all data and commands sent or received over the TCP connection.
blockMail POP Menu
Send comments on this topic.
Documentation version 3.1.
© 2009 Dart Communications. All rights reserved.