Dart.Mail Namespace > ImapMessage Class > Get Method : Get(ImapMessageInfo) Method |
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 )
Exception | Description |
---|---|
ProtocolException | Bad IMAP protocol response received from server. |
System.Net.Sockets.SocketException | A communications failure has occurred. |
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.
/// <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