Sendgrid 不发送确认邮件 asp.net core 3.1

Sendgrid does not send confirmation email asp.net core 3.1

我正在使用此 tutorial 作为帐户确认电子邮件,但我没有收到任何电子邮件或任何错误代码:

AuthMessageSenderOptions.cs

public class AuthMessageSenderOptions
{
    public string SendGridUser { get; set; }
    public string SendGridKey { get; set; }
}

appSettings.json

"AuthMessageSenderOptions": {
    "SendGridUser": "MyUserName",
    "SendGridKey": "SG.Xa................ MyKey"
},

EmailSender.cs

public class EmailSender : IEmailSender
{
    public EmailSender(IOptions<AuthMessageSenderOptions> optionsAccessor)
    {
        Options = optionsAccessor.Value;
    }

    public AuthMessageSenderOptions Options { get; } //set only via Secret Manager

    public Task SendEmailAsync(string email, string subject, string message)
    {
        return Execute(Options.SendGridKey, subject, message, email);
    }

    public Task Execute(string apiKey, string subject, string message, string email)
    {
        var client = new SendGridClient(apiKey);
        var msg = new SendGridMessage()
        {
            From = new EmailAddress("info@reloadrs.com", Options.SendGridUser),
            Subject = subject,
            PlainTextContent = message,
            HtmlContent = message
        };
        msg.AddTo(new EmailAddress(email));

        // Disable click tracking.
        // See https://sendgrid.com/docs/User_Guide/Settings/tracking.html
        msg.SetClickTracking(false, false);

        return client.SendEmailAsync(msg);
    }
}

Register.cs

var result = await _userManager.CreateAsync(user, Input.Password);
if (result.Succeeded)
{
    _logger.LogInformation("User created a new account with password.");
    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
    var confirmationLink = Url.Page(nameof(ConfirmEmail), "Account",
        new { code, email = user.Email }, Request.Scheme);
    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
        $"Please confirm your account by" +
        $" <a href='{HtmlEncoder.Default.Encode(confirmationLink)}'>clicking here</a>.");
}

我也尝试过在本地发布后尝试它,但仍然是一样的

您可以看到发送邮件的结果和错误信息:

var response = await client.SendEmailAsync(msg);
if (response.StatusCode != HttpStatusCode.OK
    && response.StatusCode != HttpStatusCode.Accepted)
{
    var errorMessage = response.Body.ReadAsStringAsync().Result;
    throw new Exception($"Failed to send mail to {to}, status code {response.StatusCode}, {errorMessage}");
}