gpt4 book ai didi

c# - 权限不足 [403] 发送电子邮件

转载 作者:太空宇宙 更新时间:2023-11-03 14:54:01 25 4
gpt4 key购买 nike

我正在尝试在我的网络应用程序中发送电子邮件(目前在本地主机中),我正在使用我用于控制台应用程序(及其工作)的下一个代码,它应该打开一个要求谷歌帐户的网页:

public async Task<String> SendEmail(String from, String text)
{
try
{
UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "-------------",
ClientSecret = "----------"
},
new[] { GmailService.Scope.GmailSend },
"user",
CancellationToken.None,
new FileDataStore(this.GetType().ToString()));

// Create Gmail API service.
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = this.GetType().ToString()
});

string plainText = "To: -------@gmail.com," + from + "\r\n" +
"Subject: T2S\r\n" +
"Content-Type: text/html; charset=us-ascii\r\n\r\n" +
text;

var newMsg = new Google.Apis.Gmail.v1.Data.Message();
newMsg.Raw = Base64UrlEncode(plainText.ToString());
service.Users.Messages.Send(newMsg, "me").Execute();
return "Done";
}
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
return "False";
}
}

private string Base64UrlEncode(string input)
{
var inputBytes = System.Text.Encoding.UTF8.GetBytes(input);
return System.Convert.ToBase64String(inputBytes).Replace("+", "-").Replace("/", "_").Replace("=", "");
}

我收到错误:

Google.Apis.Requests.RequestError

Insufficient Permission [403]

Errors [Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]

最佳答案

谢谢DalmTo事实上,它在变化中工作得很好:

将“用户”改为“XXXX”

关于c# - 权限不足 [403] 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50593523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com