I have problem with delete message from gmail server using google.apis
I can login and read messages but when I use
GmailService.Users.Messages.Delete("my-email@gmail.com", email.Id);
GmailService.Users.Threads.Delete("my-email@gmail.com", email.ThreadId);
i only delete message 'localy' in instance GmailService. When I repeat checking mail, messagess still they are... email.Id and email.ThreadId are ok, I can read messages.
I have fully rights. When I loading .json (first clean run) to authorize, gmail give me a full access. "Read, compose, send and permanently delete all emails from Gmail."
Any ideas? Some code..
private static readonly string[] Scopes = { GmailService.Scope.MailGoogleCom};
....
GmailService GmailService = new();
using (FileStream stream = new("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
credPath = System.IO.Path.Combine(credPath, ".credentials/gmail-dotnet-quickstart.json");
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.FromStream(stream).Secrets, Scopes, "ma-email@gmail.com", CancellationToken.None, new FileDataStore(credPath, true)).Result;
this.GmailService = new(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "AppName"
});
}
...
UsersResource.MessagesResource.ListRequest inboxlistRequest = GmailService.Users.Messages.List("my-email@gmail.com");
inboxlistRequest.LabelIds = "INBOX";
inboxlistRequest.IncludeSpamTrash = false;
ListMessagesResponse EmailListResponse = inboxlistRequest.Execute();
So i have 'email.Id' and 'email.ThreadId', but why i can't pernamently delete these messagess?
Any ideas?
These calls:
GmailService.Users.Messages.Delete("my-email@gmail.com", email.Id);
GmailService.Users.Threads.Delete("my-email@gmail.com", email.ThreadId);
... create requests, but don't execute them. Try:
GmailService.Users.Messages.Delete("my-email@gmail.com", email.Id).Execute();
GmailService.Users.Threads.Delete("my-email@gmail.com", email.ThreadId).Execute();