Skip to content

Working With MailFolders

Daniel Collingwood edited this page Aug 7, 2024 · 7 revisions

Getting a MailFolder

Here are a few different ways:

  1. (version 2.11.9 and beyond)
var mailFolder = await _imapReceiver.MailFolderClient.GetFolderAsync(mailFolderName, createIfNotFound: true, cancellationToken);
  1. (version 2.10.0 and beyond)
var mailFolder = await _imapReceiver.MailFolderClient.GetFolderAsync([mailFolderName], cancellationToken);
  1. (version 2.10.0 and 2.11.9 only)
var mailFolder = await mailFolder.GetOrCreateSubfolderAsync(mailFolderName, cancellationToken);

Adding Mail To A Folder

await _imapReceiver.MailFolderClient.DraftsFolder.AppendAsync(mimeMessage, cancellationToken: cancellationToken);
await _imapReceiver.MailFolderClient.AppendSentMessageAsync(mimeMessage, MessageFlags.Seen, cancellationToken);

Moving Mail Between Folders

Here are a few different ways:

  1. (version 2.11.9 and beyond)
var destinationFolder = await mailFolderClient.GetFolderAsync(mailFolderFullName, createIfNotFound: true, cancellationToken);
var uniqueId = await mailFolderClient.MoveToAsync(messageSummary, destinationFolder, cancellationToken);
  1. (version 2.10.0 and beyond)
var uniqueId = await mailFolderClient.MoveToAsync(messageSummary.UniqueId, destinationFolderFullName, cancellationToken);
  1. (version 2.10.0 and beyond)
await _imapReceiver.MailFolderClient.MoveToAsync(messageSummary, SpecialFolder.Sent, cancellationToken);
Clone this wiki locally