0

Usually in normal mail the unread status will be changed as read after we visit that mail like the same way how to find the status as read while reading email content in google api code in c#

Erik Philips
  • 53,428
  • 11
  • 128
  • 150

1 Answers1

1

Messages.modify method allows you to make changes to the message. You need to modify the message and remove the UNREAD label. The message will then appear to be read

public static Message ModifyMessage(GmailService service, String userId,
      String messageId, List<String> labelsToAdd, List<String> labelsToRemove)
  {
      ModifyMessageRequest mods = new ModifyMessageRequest();
      mods.RemoveLabelIds = "UNREAD";

      try
      {
          return service.Users.Messages.Modify(mods, userId, messageId).Execute();
      }
      catch (Exception e)
      {
          Console.WriteLine("An error occurred: " + e.Message);
      }

      return null;
  }

Not on access

This method requires one of the following scopes of access

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • 0 down vote favorite I am following this code to mark unread email as read in my gmail using Google API C# Code. This is the code return service.Users.Messages.Modify(mods, userId, messageId).Execute(); but i am getting the following error Error Google.Apis.Requests.RequestError Insufficient Permission [403] Errors [Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]] How to resolve this issue for Gmail reading using Google Api C# – user9929711 Aug 21 '18 at 05:55
  • Make sure you have your scopes set properly Check the edit on which scopes you should be using. – Linda Lawton - DaImTo Aug 21 '18 at 06:33
  • I seen your update . But where i include this url? Not on access This method requires one of the following scopes of access https://mail.google.com/ https://www.googleapis.com/auth/gmail.modify – user9929711 Aug 21 '18 at 06:47
  • Try to reauthorize the user then try again. Insufficient Permission means you dont have permission. sounds like you are using a readonly or metadata permission. If that doesnt work please edit your question and add your code so i can test it. – Linda Lawton - DaImTo Aug 21 '18 at 08:25