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.
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.
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With