a) The most straightforward way (use this if you need to download the whole message anyway):
Download the whole message as an instance of MailMessage
by calling Imap
object's GetMailMessage
method.
Access inline attachments using MailMessage
object's `Resources' collection.
Sample code:
MailMessage message = imap.GetMailMessage(uniqueId);
foreach (LinkedResource resource in message.Resources)
{
// show info about the message part
Console.WriteLine("{0} {1} {2} {3}", resource.ContentType, resource.FileName);
...
}
b) Alternatively, if you only need to download a single attachment:
Retrieve the message structure by passing the ImapListFields.MessageStructure
flag to Imap
's GetMessageInfo
or GetMessageList
method, which results in an instance of ImapMessageInfo
(or a collection in case of the GetMessageInfo
).
Call GetParts
method on ImapMessageInfo
to retrieve an array of message parts (which includes inline attachment).
Iterate through the array to find parts with Kind
of ImapMessagePartKind.LinkedResource
and determine their Id
Call Imap
object's GetMessagePart
method to download the inline attachment.
Sample code:
// retrieve a list of parts for the specific message
ImapMessageInfo info = imap.GetMessageInfo(uniqueId, ImapListFields.MessageStructure);
foreach (ImapMessagePart part in info.GetParts())
{
// show info about the message part
Console.WriteLine("{0} {1} {2} {3}", part.Id, part.Kind, part.ContentType, part.FileName);
if (part.Kind == ImapMessagePartKind.LinkedResource)
{
// download the message part if it's a linked resource
var output = new MemoryStream();
imap.GetMessagePart(uniqueId, part.Id, output);
Console.WriteLine("Message part downloaded");
...
}
}