Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to perform Archive functionality using gmail api

I am working on a app using gmail api. I want to perform archive functionality. I had gone through the api https://developers.google.com/gmail/api but unable to find any desired solutions.

Can anyone suggest me any solution for the same.

Thanks in Advance.

like image 544
Hussain Chhatriwala Avatar asked Feb 16 '16 06:02

Hussain Chhatriwala


2 Answers

A archived message is just a message that lies in the All Mail (which isn't an actual label). You can achieve this by removing the INBOX-label on the message (or any other label you have added to it), which can be achieved with modify.

like image 164
Tholle Avatar answered Oct 14 '22 05:10

Tholle


  C# Code for Gmail APIs Archive email by using OAuth 2.0 service.   
     class ReadAllMails
      {       
        static string[] Scopes = { GmailService.Scope.MailGoogleCom };
        static string ApplicationName = "Gmail API .NET Quickstart";
        static void Main(string[] args)
        {
          UserCredential credential;
          using (var stream =
          new FileStream("credentials_dev.json", FileMode.Open, FileAccess.Read))
          {
               string credPath = "token_MailGoogleCom.json";
               credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
               GoogleClientSecrets.Load(stream).Secrets,
               Scopes,
               "user",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;                      
             }

            var service = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = ApplicationName,
            }); 

            List<string> lableIds = new List<string>();
            lableIds.Add("INBOX");
            ModifyMessageRequest mods = new ModifyMessageRequest();
            mods.RemoveLabelIds= lableIds;
            service.Users.Messages.Modify(mods, "me", emailId).Execute();
            //emailId that you want to archive
       }
    }
like image 37
shiva samalla Avatar answered Oct 14 '22 03:10

shiva samalla