PowerTCP Mail for .NET
Decoding Attachments as Files
Send comments on this topic.



Glossary Item Box

When getting mail from a POP server, attachments are decoded in one of two ways:

This value defaults to false as attachments can be quite large, sometimes even exceeding the memory capacity.

To get all messages and decode attachments and store them as files.

  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. After login successfully occurs, logout will automatically occur (since Pop.AutoLogout = true). 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, allowing full access to all parts of the message, including attachments. For this example, the next step is to save all of the attachments for all of the messages. The following example demonstrates saving all attachments for all messages.
    C# Copy Code
    // Save attachments for all messages.
    foreach(Dart.PowerTCP.PopMessage msg in pop1.Messages)
    {
       foreach(Dart.PowerTCP.AttachmentStream att in msg.Message.Attachments)
       {
          string filename = "C:\\temp\\" + att.FileName;
          att.Save(filename, true);
       }
    }
    Visual Basic Copy Code
    ' Save attachments for all messages.
    Dim msg As PopMessage
    For Each msg In Pop1.Messages
       Dim att As AttachmentStream
       For Each att In msg.Message.Attachments
          Dim filename As String = "C:\temp\" & att.FileName
          att.Save(filename, true)
       Next
    Next
  7. Compile and run the application. If any messages contained attachments, they will be found in the specified directory ("C:\Temp").
Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.