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



Glossary Item Box

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.

  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 to the form.
  4. Set the properties required to properly get all messages 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 messages.
    pop1.AutoGet = MessageSection.Complete;
    Visual Basic Copy Code
    ' Be sure the Pop component is configured to automatically retrieve messages.
    Pop1.AutoGet = Complete
  5. 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. 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 messages have been retrieved. Display the number of messages retrieved to the user.
    C# Copy Code
    Debug.WriteLine(pop1.Messages.Length + " messages retrieved.");
    Visual Basic Copy Code
    Debug.WriteLine(Pop1.Messages.Length & " messages retrieved.")
  7. 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. Access message data. For this example, do something trivial like display the number of attachments for each message.
    C# Copy Code
    // 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 Copy Code
    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
Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.