This is the English version of the forums. Can you please translate the error message information that you're getting into English so we know what it says. The general gist appears to just be an unsuccessful HTTP status code so you should probably consider doing this test using Postman or curl or similar tool so you can see the raw HTTP request and response.
Mark a Mail as Read/Unread not working | Graph API | C#
Th3TV
46
Reputation points
I want to mark my mails as read/unread via the Graph API, but right now I have a code which does not work.
The Mail should update in the MailClient, like when you open to read it.
Can anyone tell me how to fix this issue or does anyone have a better code example for me?
Error code:
Program.cs
mailHelper.Init("{TenantID}", "{ClientID}", "{ClientSecret}");
var user = mailHelper.GetUser("{UserMail}");
var emailsOfUser = mailHelper.GetEmails(user.Id);
foreach (var curMail in emailsOfUser)
{
try
{
mailHelper.MessageMarkReaOrUnRead(curMail.Id, true); /// todo
}
catch (Exception exLoopMsg)
{
Console.WriteLine(exLoopMsg.Message);
}
}
Mail.cs
/// <summary>
///
/// </summary>
/// <param name="messageIds"></param>
/// <param name="markAsRead"></param>
/// <param name="scopes"></param>
/// <returns></returns>
public bool? MessageMarkReaOrUnRead(List<string> messageIds, bool markAsRead, string[] scopes = null)
{
return MessageMarkReaOrUnReadAsync(messageIds, markAsRead, scopes).GetAwaiter().GetResult();
}
/* ------------------------------------------------------------ */
/// <summary>
///
/// </summary>
/// <param name="messageIds"></param>
/// <param name="markAsRead"></param>
/// <param name="scopes"></param>
/// <returns></returns>
public bool? MessageMarkReaOrUnRead(string messageId, bool markAsRead, string[] scopes = null)
{
List<string> messageIds = new List<string>();
messageIds.Add(messageId);
return MessageMarkReaOrUnReadAsync(messageIds, markAsRead, scopes).GetAwaiter().GetResult();
}
/* ------------------------------------------------------------ */
private async Task<bool?> MessageMarkReaOrUnReadAsync(List<string> messageIds, bool markAsRead, string[] scopes = null)
{
GraphServiceClient graphServiceClient = this.GetAuthenticatedGraphClient(scopes);
bool? result;
if (markAsRead == true)
{
result = await graphServiceClient.Admin.ServiceAnnouncement.Messages
.MarkRead(messageIds)
.Request()
.PostAsync();
}
else
{
result = await graphServiceClient.Admin.ServiceAnnouncement.Messages
.MarkUnread(messageIds)
.Request()
.PostAsync();
}
return result;
}