Add Custom Flags to Messages using Aspose.Email for .NET 17.6

Share on FacebookTweet about this on TwitterShare on LinkedIn

We are pleased to announce the release of Aspose.Email for .NET 17.6. It includes new features and enhancements related to various functional areas of the API. Specifically, the enhancements are related to the API’s IMAP, EWS client and rendering of messages to MHTML. The API also fixes several bugs that further improve the performance and functionality of the API. For a complete list of what is new and fixed, please visit the release notes section of API documentation.

New Features and Enhancements

Adding Custom Flag to Messages using IMAP: This month’s release introduces a new feature of adding custom flags to a message on the server using the API’s ImapClient. Custom flags can be added to a message using the AddMessageFlags method using the ImageMessageFlags. This is as illustrated in the code sample below.

// Create a message
MailMessage message = new MailMessage("user@domain1.com", "user@domain2.com", "subject", "message");

//Append the message to mailbox
string uid = client.AppendMessage(ImapFolderInfo.InBox, message);

//Add custom flags to the added messge
client.AddMessageFlags(uid, ImapMessageFlags.Keyword("custom1") | ImapMessageFlags.Keyword("custom1_0"));

//Retreive the messages for checking the presence of custom flag
client.SelectFolder(ImapFolderInfo.InBox);

ImapMessageInfoCollection messageInfos = client.ListMessages();
foreach (var inf in messageInfos)
{
    ImapMessageFlags[] flags = inf.Flags.Split();

    if (inf.ContainsKeyword("custom1"))
        Console.WriteLine("Keyword found");
}

Filtering Messages based on Custom Flags: Not only you can add custom flags to messages on server using the API’s ImapClient, you can also filter messages by specifying custom flags. The ImapQueryBuilder’s HasFlags and HasNoFlags can be used for this purpose as shown in code sample below.

ImapQueryBuilder queryBuilder = new ImapQueryBuilder();

queryBuilder.HasFlags(ImapMessageFlags.Keyword("custom1"));

queryBuilder.HasNoFlags(ImapMessageFlags.Keyword("custom2"));

Skipping Inline Images during Email Conversion: Email messages with multiple or large size images embedded in them can take considerable time and system resources during conversion to MHTML format. This month’s release provides the capability to skip inline images from including in output MHTML using the MhtSaveOptions class’s SkipInlineImages property. Setting this flag avoids writing inline images from message body to output MHTML.

mhtSaveOptions.SkipInlineImages = true;

eml.Save(Path.Combine(dataDir, "EmlToMhtmlWithoutInlineImages_out.mht"), mhtSaveOptions);

API Resources

The following API resources can be of help to you in getting started with Aspose.Email API.