[英]Gmail API to access, read/modify the delegated emails or shared gmail using C#
I can read/modify gmails from my own Gmail account via Gmail API using its credentials.我可以使用其凭据通过 Gmail API 从我自己的 Gmail 帐户读取/修改 gmail。
using Google.Apis.Auth.OAuth2;
using Google.Apis.Gmail.v1;
But now, IT operation provide me a shared Gmail or delegate Gmail account.但是现在,IT 运营为我提供了一个共享的 Gmail 或委托 Gmail 帐户。 So I want to access, read/modify from that delegate email .
所以我想从该委托电子邮件中访问、读取/修改。
How can I access and read delegate gmail using Gmail API?如何使用 Gmail API 访问和阅读委托 gmail? Is there any example?
有没有例子?
Most of the code in Gmail API sites are in Python and Java which I don't understand. Gmail API 站点中的大部分代码都是用我不理解的 Python 和 Java 编写的。
please shed some lights.请放一些灯。
What I have tried:我试过的:
I can access, read my own mail by using Gmail API -我可以使用 Gmail API 访问、阅读我自己的邮件 -
private static string[] Scopes = { GmailService.Scope.GmailModify };
private UserCredential _credential;
private string credPath = "token.json";
public UserCredential GetCredential()
{
using (var stream =
new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
{
_credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
return _credential;
}
GmailCredentials Info = new GmailCredentials();
private static string ApplicationName = "xxxxx";
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = GetCredential(),
ApplicationName = ApplicationName,
});
UsersResource.MessagesResource.ListRequest request = service.Users.Messages.List("me");
request.Q = ConfigurationManager.AppSettings["filter"];
request.MaxResults = Convert.ToInt64(ConfigurationManager.AppSettings["maxCount"]); //5;
messages = request.Execute().Messages;
List<string> lstRemove = new List<string>() { "UNREAD" };
/// Read the individual message and output as List<Email>
for (int index = 0; index < messages.Count; index++)
{
//... Do the code...
}
Gmail API does not work with delegated mailboxes. Gmail API 不适用于委托邮箱。 Only the user's own mailbox is accessible.
只能访问用户自己的邮箱。 To access all user mail in the G Suite domain, try using service account and domain-wide delegation .
要访问 G Suite 域中的所有用户邮件,请尝试使用 service account 和domain-wide delegation 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.