MailClient.GetCategories Method

Receives a specified email's categories from Office 365 or Exchange Server.

[Visual Basic]
Public Function GetCategories( _
    info As MailInfo
) As CategoryCollection
public CategoryCollection GetCategories(
    MailInfo info
public: CategoryCollection^ GetCategories(
    MailInfo^ info
public function GetCategories( 
    info: MailInfo
) : CategoryCollection;


The MailInfo instance to retrieve the categories.

Return Value

A CategoryCollection object.


This method retrieves email's categories, it only supports EWS and Graph API protocol. If you have set GetMailInfosParam.GetMailInfosOptions.GetCategories, you can get the categories from MailInfo.Categories property directly after calling GetMailInfos method.


var client = new MailClient("TryIt");
// you must use EWS or Graph API to connect the server

// retrieve categories and follow up flag to MailInfo
client.GetMailInfosParam.GetMailInfosOptions |= GetMailInfosOptionType.GetCategories;
client.GetMailInfosParam.GetMailInfosOptions |= GetMailInfosOptionType.GetFollowUpFlag;
var mailInfos = client.GetMailInfos();
Console.WriteLine("Total {0} emails", mailInfos.Length);
for (int i = 0; i < mailInfos.Length; i++)
    // if you have set GetMailInfosOptionType.GetCategories flag, you don't need to call this method
    Console.WriteLine(string.Format("Index: {0}", mailInfos[i].Index));
    Console.WriteLine(string.Format("Categories: {0}", _categoriesToString(mailInfos[i].Categories)));

static CategoryCollection _stringToCategories(string input)
    var categories = new CategoryCollection();
    string[] values = input.Split(',');
    for(int i = 0; i < values.Length; i++)
        string value = values[i].Trim();
            categories.Add(new Category(value));
    return categories;

static string _categoriesToString(CategoryCollection categories)
    if (categories == null || categories.Count == 0)
        return "None";

    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < categories.Count; i++)
        if (i < categories.Count - 1)
    return buffer.ToString();

See Also

MailClient.GetMail Method
Mail Class