| MailFolderGetStream(UniqueId, BodyPart, CancellationToken, ITransferProgress) Method |
Get a body part as a stream.
Namespace: MailKitAssembly: MailKit (in MailKit.dll) Version: 4.7.1
Syntax Exceptions Remarks
Gets a body part as a stream.
Example public static void CacheBodyParts (string baseDirectory)
{
using (var client = new ImapClient ()) {
client.Connect ("imap.gmail.com", 993, SecureSocketOptions.SslOnConnect);
client.Authenticate ("username", "password");
client.Inbox.Open (FolderAccess.ReadOnly);
var query = SearchQuery.SubjectContains ("MimeKit").Or (SearchQuery.SubjectContains ("MailKit"));
var uids = client.Inbox.Search (query);
var items = client.Inbox.Fetch (uids, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure);
foreach (var item in items) {
var directory = Path.Combine (baseDirectory, item.UniqueId.ToString ());
Directory.CreateDirectory (directory);
foreach (var bodyPart in item.BodyParts) {
using (var stream = client.Inbox.GetStream (item.UniqueId, bodyPart)) {
var path = Path.Combine (directory, bodyPart.PartSpecifier);
using (var output = File.Create (path))
stream.CopyTo (output);
}
}
}
client.Disconnect (true);
}
}
See Also