【发布时间】:2020-03-08 13:33:37
【问题描述】:
我的目标是检索我的 gmail 帐户中一个标签下存在的所有电子邮件,并将这些电子邮件转发到另一个电子邮件地址。这是我目前所拥有的:
string[] Scopes = { GmailService.Scope.GmailReadonly, GmailService.Scope.GmailSend, };
string ApplicationName = "APP NAME";
UserCredential credential;
using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
{
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
var labelList = service.Users.Messages.List("me@gmail.com");
labelList.LabelIds = "LABEL_NAME";
var emailListResponse = labelList.Execute();
if (emailListResponse != null && emailListResponse.Messages != null)
{
foreach (var email in emailListResponse.Messages)
{
//THIS IS WHERE I WOULD LIKE TO FORWARD this email TO ANOTHER EMAIL ADDRESS?
//How to set TO?
//service.Users.Messages.Send(email, "me@gmail.com").Execute();
}
}
我可以检索电子邮件,但我不知道如何转发。谢谢你的帮助
【问题讨论】:
-
我绝对认为会有一种更简单的方法来转发现有消息,但看起来并非如此。感谢此链接