aravind  sasi

aravind sasi

  • NA
  • 113
  • 2.7k

Gmail API to access, read/modify the delegated emails

May 2 2019 7:46 AM
Hi,
 
I can read/modify gmails from my own Gmail account via Gmail API using its credentials
 
using Google.Apis.Auth.OAuth2;
using Google.Apis.Gmail.v1;
 
But now, IT operation provide me a shared Gmail or delegate. So I want to access, read/modify from that delegate email. So I have to access that delegate email ([email protected]).
 
How can I access delegate email using Gmail API?
 
Is there any example?
 
Most of the code in Gmail API sites are in Python and Java which I don't understand.
 
please shed some lights..
 
I can access, read my own mail by using Gmail API -
  1. private static string[] Scopes = { GmailService.Scope.GmailModify };  
  2. private UserCredential _credential;  
  3. private string credPath = "token.json";  
  4. public UserCredential GetCredential()  
  5. {  
  6. using (var stream =  
  7. new FileStream("credentials.json", FileMode.Open, FileAccess.Read))  
  8. {  
  9. _credential = GoogleWebAuthorizationBroker.AuthorizeAsync(  
  10. GoogleClientSecrets.Load(stream).Secrets,  
  11. Scopes,  
  12. "user",  
  13. CancellationToken.None,  
  14. new FileDataStore(credPath, true)).Result;  
  15. }  
  16. return _credential;  
  17. }  
  1. GmailCredentials Info = new GmailCredentials();  
  2. private static string ApplicationName = "xxxxx";  
  3. var service = new GmailService(new BaseClientService.Initializer()  
  4. {  
  5. HttpClientInitializer = GetCredential(),  
  6. ApplicationName = ApplicationName,  
  7. });  
  8. UsersResource.MessagesResource.ListRequest request = service.Users.Messages.List("me");  
  9. request.Q = ConfigurationManager.AppSettings["filter"];  
  10. request.MaxResults = Convert.ToInt64(ConfigurationManager.AppSettings["maxCount"]); //5;  
  11. messages = request.Execute().Messages;  
  12. List<string> lstRemove = new List<string>() { "UNREAD" };  
  13. /// Read the individual message and output as List<Email>  
  14. for (int index = 0; index < messages.Count; index++)  
  15. {  
  16. //... Do the code...  
  17. }  

Answers (4)