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

Insufficient Permission [403] sending email

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

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 确实它在更改后工作得很好:

将 "user" 更改为 "XXXX"