PowerTCP Mail for .NET
Get() Method
Example 




Gets the message.
Syntax
Public Overloads Sub Get() 
Dim instance As ImapMessage
 
instance.Get()
public void Get()
public: void Get(); 
public:
void Get(); 
Exceptions
ExceptionDescription
ProtocolExceptionBad IMAP protocol response received from server.
System.Net.Sockets.SocketExceptionA communications failure has occurred.
Remarks
Gets a single message, including flags, internal date and UID and populates MessageBase.Message. Use Mailbox.Get to get all messages in a mailbox.
Example
This example demonstrates two methods of downloading all emails in the current mailbox, and saving them to disk.
/// <summary>
/// Downloads each message in the current mailbox and saves it to the specified directory.
/// </summary>
/// <param name="myImap">A connected and authenticated Imap instance, that has a mailbox selected.</param>
/// <param name="downloadFolder">The directory to save the emails in.</param>
public void GetMessagesInterleaved(Imap myImap, string downloadFolder)
{
    foreach (ImapMessage message in myImap.SelectedMailbox.ToArray())
    {
        //Confirm that the message in the copied array wasn't deleted by another client
        if (message.Id != 0)
        {
            message.Get();
            message.Message.Save(Path.Combine(downloadFolder, message.Uid + ".eml"));
        }
    }
}

/// <summary>
/// Downloads all messages in the current mailbox and then saves them to the specified directory.
/// </summary>
/// <param name="myImap">A connected and authenticated Imap instance, that has a mailbox selected.</param>
/// <param name="downloadFolder">The directory to save the emails in.</param>
public void GetMessages(Imap myImap, string downloadFolder)
{
    ImapMessage[] messages = myImap.SelectedMailbox.Get();
    foreach (ImapMessage message in messages)
        message.Message.Save(Path.Combine(downloadFolder, message.Uid + ".eml"));
}
''' <summary>
''' Downloads each message in the current mailbox and saves it to the specified directory.
''' </summary>
''' <param name="myImap">A connected and authenticated Imap instance, that has a mailbox selected.</param>
''' <param name="downloadFolder">The directory to save the emails in.</param>
Public Sub GetMessagesInterleaved(ByVal myImap As Imap, ByVal downloadFolder As String)
    For Each message As ImapMessage In myImap.SelectedMailbox.ToArray()
        'Confirm that the message in the copied array wasn't deleted by another client
        If message.Id <> 0 Then
            message.Get()
            message.Message.Save(Path.Combine(downloadFolder, message.Uid & ".eml"))
        End If
    Next message
End Sub

''' <summary>
''' Downloads all messages in the current mailbox and then saves them to the specified directory.
''' </summary>
''' <param name="myImap">A connected and authenticated Imap instance, that has a mailbox selected.</param>
''' <param name="downloadFolder">The directory to save the emails in.</param>
Public Sub GetMessages(ByVal myImap As Imap, ByVal downloadFolder As String)
    Dim messages() As ImapMessage = myImap.SelectedMailbox.Get()
    For Each message As ImapMessage In messages
        message.Message.Save(Path.Combine(downloadFolder, message.Uid & ".eml"))
    Next message
End Sub
See Also

Reference

ImapMessage Class
ImapMessage Members
Overload List


PowerTCP Mail for .NET Documentation Version 4.3
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic