Send an email in c# with category already set.

Ward Horsfall 101 Reputation points


How can I send a message using C# and using a category already set - so when it comes into the Inbox the category is already available.

So for example assuming I have a master category called "C1"

Then I can have some code to send a message and mark it as "C1"

Then read inbox and see "C1" category.



Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,390 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sheena-MSFT 1,731 Reputation points

    Hi @Ward Horsfall ,

    Using Graph API you can first create a draft message with category property.

    Please find the below c# code for the same:

    GraphServiceClient graphClient = new GraphServiceClient( authProvider );  
    var message = new Message  
    	Subject = "Did you see last ",  
    	Importance = Importance.Low,  
    	Categories = new List<String>()  
    		"Blue category"  
    	Body = new ItemBody  
    		ContentType = BodyType.Html,  
    		Content = "They were <b>awesome</b>!"  
    	ToRecipients = new List<Recipient>()  
    		new Recipient  
    			EmailAddress = new EmailAddress  
    				Address = ""  
    await graphClient.Me.Messages  

    It will create a draft message with category as shown below


    Then you have to send mail using the message id created in the above step.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment".