PowerTCP Mail for .NET
Get(ImapMessageInfo) Method
Example 




Message sections to update.
Gets the specified message sections.
Syntax
Public Overloads Sub Get( _
   ByVal sections As ImapMessageInfo _
) 
Dim instance As ImapMessage
Dim sections As ImapMessageInfo
 
instance.Get(sections)
public void Get( 
   ImapMessageInfo sections
)
public: void Get( 
   ImapMessageInfo sections
) 
public:
void Get( 
   ImapMessageInfo sections
) 

Parameters

sections
Message sections to update.
Exceptions
ExceptionDescription
ProtocolExceptionBad IMAP protocol response received from server.
System.Net.Sockets.SocketExceptionA communications failure has occurred.
Remarks

A combination of of ImapMessageInfo can be used to selectively populate MessageBase.Message.

For example, ImapMessageInfo.Structure can be used to populate Message with parts that have no data. GetPart can subsequently be used to get data for any Part in Parts.

Example
This example demonstrates how to download the attachments of a message, without downloading the entire message.
/// <summary>
/// Downloads all attachments from the first email that contains attachments.
/// </summary>
/// <param name="myImap">A connected and authenticated Imap instance, that has a mailbox selected.</param>
/// <param name="saveDir">Path of the directory to save the attachments in.</param>
public void GetMessageAttachments(Imap myImap, string saveDir)
{
    //Discover attachments by retrieving email BodyStructure, 
    //then download the attachments using GetPart()
    foreach (ImapMessage imapMessage in myImap.SelectedMailbox.ToArray())
    {
        imapMessage.Get(ImapMessageInfo.Structure);
        if (imapMessage.Message.Attachments.Count > 0)
        {
            foreach (Attachment attachment in imapMessage.Message.Attachments)
            {
                imapMessage.GetPart(attachment, false);
                attachment.Content.MoveTo(Path.Combine(saveDir, attachment.FileName));
            }
            break;
        }
    }
}
''' <summary>
''' Downloads all attachments from the first email that contains attachments.
''' </summary>
''' <param name="myImap">A connected and authenticated Imap instance, that has a mailbox selected.</param>
''' <param name="saveDir">Path of the directory to save the attachments in.</param>
Public Sub GetMessageAttachments(ByVal myImap As Imap, ByVal saveDir As String)
    'Discover attachments by retrieving email BodyStructure, 
    'then download the attachments using GetPart()
    For Each imapMessage As ImapMessage In myImap.SelectedMailbox.ToArray()
        imapMessage.Get(ImapMessageInfo.Structure)
        If imapMessage.Message.Attachments.Count > 0 Then
            For Each attachment As Attachment In imapMessage.Message.Attachments
                imapMessage.GetPart(attachment, False)
                attachment.Content.MoveTo(Path.Combine(saveDir, attachment.FileName))
            Next attachment
            Exit For
        End If
    Next imapMessage
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