PowerTCP Mail for .NET
Get() Method
Example 




Retrieves all of the messages contained in the mailbox.
Syntax
Public Overloads Function Get() As ImapMessage()
Dim instance As Mailbox
Dim value() As ImapMessage
 
value = instance.Get()
public ImapMessage[] Get()
public: ImapMessage*[]* Get(); 
public:
array<ImapMessage^>^ Get(); 

Return Value

Array of ImapMessage objects retrieved.
Exceptions
ExceptionDescription
ProtocolExceptionBad IMAP protocol response received from server.
Remarks
Retrieves the messages contained in this mailbox and populates the collection. This method uses the IMAP FETCH command and UUIDs to retrieve message content. This method is useful for bulk operations. Use Get to retrieve a single message.
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

Mailbox Class
Mailbox Members
Overload List


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