-
-
Notifications
You must be signed in to change notification settings - Fork 10
Working With MailFolders
Daniel Collingwood edited this page Jun 21, 2024
·
7 revisions
Here are a few different ways:
- (any release or pre-release after version 2.10.0)
var mailFolder = await _imapReceiver.MailFolderClient.GetFolderAsync([mailFolderName], cancellationToken);
- (any release or pre-release after version 2.10.0)
var mailFolder = await _imapReceiver.MailFolderClient.GetOrCreateFolderAsync(mailFolderName, cancellationToken);
- (any release or pre-release after version 2.10.0)
var mailFolder = await _imapReceiver.ImapClient.Inbox.GetOrCreateSubfolderAsync(mailFolderName, cancellationToken);
- (version 2.10.0)
var mailFolder = await messageSummary.Folder.GetOrCreateSubfolderAsync(mailFolderName, cancellationToken);
- (version 2.10.0 or below)
public static async Task<IMailFolder> GetOrCreateSubfolderAsync(this IMailFolder baseFolder, string mailFolderName, CancellationToken cancellationToken = default)
{
IMailFolder mailFolder;
try
{
mailFolder = await baseFolder.GetSubfolderAsync(mailFolderName, cancellationToken);
}
catch (FolderNotFoundException)
{
mailFolder = await baseFolder.CreateAsync(mailFolderName, isMessageFolder: true, cancellationToken);
}
return mailFolder;
}
await _imapReceiver.MailFolderClient.DraftsFolder.AppendAsync(mimeMessage);
private async Task MoveToDestinationAsync(IMessageSummary messageSummary, string destinationFolderName, CancellationToken cancellationToken = default)
{
var destinationFolder = await _imapReceiver.MailFolderClient.GetFolderAsync([destinationFolderName], cancellationToken);
await messageSummary.MoveToAsync(destinationFolder, cancellationToken);
}