ASP.NET Core 2.2.1 Hosting Tips: How To Read Gmail Inbox From Google API?
Notice: A non well formed numeric value encountered in /home/cheaphosting/public_html/reliablehostingasp.net/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118
Notice: A non well formed numeric value encountered in /home/cheaphosting/public_html/reliablehostingasp.net/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119
Notice: A non well formed numeric value encountered in /home/cheaphosting/public_html/reliablehostingasp.net/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118
Notice: A non well formed numeric value encountered in /home/cheaphosting/public_html/reliablehostingasp.net/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119
In this tutorial, i will explain you about How To Read Gmail Inbox from Google Api (from, date , subject , body of the email). To Read Gmail Inbox from Google Api (from, date , subject , body of the email). In this section we are going to see about reading Gmail inbox from Google api. Please use your email id for configuration and do not share secret key to anyone.
Please refer below link to get your client secret key from Google
https://developers.google.com/gmail/api/quickstart/dotnet
You can able to get from, date, subject and body of the email.
To connect Google Api with client secret key
1 2 3 4 5 6 7 8 9 10 11 12 | using(var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) { string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath, ".credentials/gmail-dotnet-quickstart.json"); credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } foreach(MessagePart p in emailInfoResponse.Payload.Parts) { if (p.MimeType == "text/html") { byte[] data = FromBase64ForUrlString(p.Body.Data); string decodedString = Encoding.UTF8.GetString(data); } } |
C#