Send an email in c# with category already set.

Ward Horsfall 101 Reputation points
2022-05-07T11:14:24.65+00:00

Hi,

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.

Thanks

Ward

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
    2022-05-11T12:17:00.963+00:00

    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 = "test1@raiinfy.onmicrosoft.com"  
    			}  
    		}  
    	}  
    };  
      
    await graphClient.Me.Messages  
    	.Request()  
    	.AddAsync(message);  
    

    It will create a draft message with category as shown below

    201061-category2.png

    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".