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.
- 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.
- 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 - 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")
- At this point, all messages have been retrieved. Display the number of messages retrieved to the user.
C#
Copy CodeDebug.WriteLine(pop1.Messages.Length + " messages retrieved.");Visual Basic
Copy CodeDebug.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. 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 CodeDim 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