Gmail API 访问,read/modify 使用 C# 的委托电子邮件或共享 gmail
Gmail API to access, read/modify the delegated emails or shared gmail using C#
我可以 read/modify 使用 Gmail 凭据通过 Gmail API 从我自己的 Gmail 帐户发送 gmail。
using Google.Apis.Auth.OAuth2;
using Google.Apis.Gmail.v1;
但现在,IT 运营为我提供了一个 共享 Gmail 或委托 Gmail 帐户。所以我想从该委托电子邮件 .
访问 read/modify
如何使用 Gmail API 访问和阅读委托 gmail?
有例子吗?
Gmail API 站点中的大部分代码都在 Python 和 Java 中,我不明白。
请发光。
我尝试过的:
我可以使用 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 不适用于委托邮箱。只能访问用户自己的邮箱。要访问 G Suite 域中的所有用户邮件,请尝试使用服务帐户和 domain-wide delegation.
我可以 read/modify 使用 Gmail 凭据通过 Gmail API 从我自己的 Gmail 帐户发送 gmail。
using Google.Apis.Auth.OAuth2;
using Google.Apis.Gmail.v1;
但现在,IT 运营为我提供了一个 共享 Gmail 或委托 Gmail 帐户。所以我想从该委托电子邮件 .
访问 read/modify如何使用 Gmail API 访问和阅读委托 gmail? 有例子吗?
Gmail API 站点中的大部分代码都在 Python 和 Java 中,我不明白。
请发光。
我尝试过的:
我可以使用 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 不适用于委托邮箱。只能访问用户自己的邮箱。要访问 G Suite 域中的所有用户邮件,请尝试使用服务帐户和 domain-wide delegation.