Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

c# Google.Apis.Gmail GmailService delete message

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading