Getting message attachments |
Upon retrieving an email message from a mailbox you can get any attachments to the email using the GetAttachments method. Any attachments found are returned as an Enumeration.
Example
[C#] myImap.Connect(); IEnumerator e = myImap.GetMessages(); while(e.MoveNext()) { EmailMessage message = (EmailMessage)e.Current; // get attachments for email IEnumerator ea = message.GetAttachments(); while(ea.MoveNext()) { Attachment a = (Attachment)ea.Current; // get name of attached file String filename = a.GetFilename(); // get data for attached file byte[] data = a.GetFileData(); // process the attachment } }
[Visual Basic] myImap.Connect() Dim e As IEnumerator = myImap.GetMessages() Dim message As EmailMessage = Nothing While (e.MoveNext()) message = e.Current Dim a As IEnumerator = message.GetAttachments() While (a.MoveNext()) attachment = a.Current ' get name of attached file Dim filename As String = attachment.GetFilename() ' get data for attached file Dim data As Byte() = attachment.GetFileData() ' process the attachment End While End While
|