Aspose.Email for .NET 22.5 Release Notes

All Changes

EMAILNET-40450Implement IAsyncImapClientEnhancement
EMAILNET-40452Implement IAsyncSmtpClientEnhancement
EMAILNET-40451Implement IAsyncPop3ClientEnhancement
EMAILNET-40596Graph client - reading unread messages with pagingFeature
EMAILNET-40591Performance issue while migrating mails to office 365Bug
EMAILNET-40574Creating MSG file issue with RTF embedded contentBug
EMAILNET-40605Maximum number of headers in one message should be less than or equal to 5.Bug
EMAILNET-40597Re-saving EML loses the calendar appointment message partBug
EMAILNET-40595MailMessage.Date returns Current Date for MSG fileBug
EMAILNET-40593Attachments are lost after EML to MSGBug

New Features

Enumerating Messages with Paging Support using Graph Client

The API provides the paging and filtering support for listing messages. This is very helpful where the mailbox has a large number of messages and requires a lot of time for retrieving the summary information about these.

List Messages from Exchange Server using IGraphClient

//  reading unread messages with paging
using var client = GraphClient.GetClient(tokenProvider, config.Tenant);

// paging option
var itemsPerPage = 10;
// create unread messages filter
GraphQueryBuilder builder = new GraphQueryBuilder();
var query = builder.GetQuery();

// list messages
var pageInfo = client.ListMessages(KnownFolders.Inbox, new PageInfo(itemsPerPage), query);
var  messages = pageInfo.Items;

while (!pageInfo.LastPage)
    pageInfo = client.ListMessages(KnownFolders.Inbox, pageInfo.NextPage, query);

// set messages state as read
foreach (var message in messages)

A new approach to handling mail clients in asynchronous mode

We have added the following changes to the public API:

  • IAsyncSmtpClient - Allows applications to send messages by using the Simple Mail Transfer Protocol (SMTP).

  • SmtpClient.CreateAsync - Creates a new instance of the Aspose.Email.Clients.Smtp.SmtpClient class

  • SmtpSend - Aspose.Email.Clients.Smtp.IAsyncSmtpClient.SendAsync(Aspose.Email.Clients.Smtp.Models.SmtpSend) method parameter set.

  • SmtpForward - The Aspose.Email.Clients.Smtp.IAsyncSmtpClient.ForwardAsync(Aspose.Email.Clients.Smtp.Models.SmtpForward) arguments.

  • IAsyncImapClient - Allows applications to access and manipulate messages by using the Internet Message Access Protocol (IMAP).

  • ImapClient.CreateAsync - Creates a new instance of the Aspose.Email.Clients.Imap.ImapClientclass

Code example

static readonly string tenantId = "YOU_TENANT_ID";
static readonly string clientId = "YOU_CLIENT_ID";
static readonly string redirectUri = "http://localhost";
static readonly string username = "username";
static readonly string[] scopes = { "", "" };

static async Task Main(string[] args)
    await SmtpAsync();
    await ImapAsync();

static async Task SmtpAsync()
    var tokenProvider = new TokenProvider(clientId, tenantId, redirectUri, scopes);
    var client = SmtpClient.CreateAsync("", username, tokenProvider, 587).GetAwaiter().GetResult();
    var eml = new MailMessage("", "", "test subj async", "test body async");
    // send message
    var sendOptions = SmtpSend.Create();
    await client.SendAsync(sendOptions);
    Console.WriteLine("message was sent");

    // forward message
    var fwdOptions = SmtpForward.Create();
    await client.ForwardAsync(fwdOptions);
    Console.WriteLine("message was forwarded");

static async Task ImapAsync()
    var tokenProvider = new TokenProvider(clientId, tenantId, redirectUri, scopes);
    var client = ImapClient.CreateAsync("", username, tokenProvider, 993).GetAwaiter().GetResult();
    await client.SelectFolderAsync(ImapFolderInfo.InBox);
    var messages = await client.ListMessagesAsync();
    Console.WriteLine("Messages :" + messages.Count);

public class TokenProvider : IAsyncTokenProvider
    private readonly PublicClientApplicationOptions _pcaOptions;
    private readonly string[] _scopes;

    public TokenProvider(string clientId, string tenantId, string redirectUri, string[] scopes)
        _pcaOptions = new PublicClientApplicationOptions
            ClientId = clientId,
            TenantId = tenantId,
            RedirectUri = redirectUri

        _scopes = scopes;

    public async Task<OAuthToken> GetAccessTokenAsync(bool ignoreExistingToken = false, CancellationToken cancellationToken = default)

        var pca = PublicClientApplicationBuilder

            var result = await pca.AcquireTokenInteractive(_scopes)

            return new OAuthToken(result.AccessToken);
        catch (MsalException ex)
            Console.WriteLine($"Error acquiring access token: {ex}");
        catch (Exception ex)
            Console.WriteLine($"Error: {ex}");

        return null;

    public void Dispose()