Decoding Attachments As Files
When getting mail from a POP server, attachments are decoded in one of two ways:
- Set UseMemoryStreams to false and attachments are decoded and stored as files.
- Set UseMemoryStreams to true and attachments are decoded and stored as MemoryStreams.
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.
- 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. After login successfully occurs, logout will automatically occur (since Pop.AutoLogout = true).
[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, 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.
[Visual Basic, C#]
[C#]
// 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]
' 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
- Compile and run the application. If any messages contained attachments, they will be found in the specified directory ("C:\Temp").
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.
Mail POP Menublock
Send comments on this topic.
Documentation version 3.1.
© 2009 Dart Communications. All rights reserved.