1

In startup.cs I have:

 services.AddTransient<IEmailSender, EmailSender>();
 services.Configure<AuthMessageSenderOptions>(Configuration);

In EmailSender class I have:

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

public Task Execute( string subject, string message, string email)
{
    var apiKey = Environment.GetEnvironmentVariable("KEY");
    //var client = new SendGridClient(apiKey);
    var client = new SendGridClient(apiKey);
    var msg = new SendGridMessage()
        {
            From = new EmailAddress("Joe@contoso.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);
}

I am getting this page instead of sending mail.As refereed to Microsoft documentation I do not have /Identity/Account/Manage/PersonalData page also.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rupak
  • 409
  • 1
  • 3
  • 18
  • 1
    The PersonalData page is missing cause its not scaffold out by default unless you tell it to. Copy and Paste appears to be part of the problem here since you have default information based on example versus an actual account to use sendgrid. – mvermef Jan 12 '20 at 21:36

1 Answers1

0

Haven't used SendGrid before, but based on the URL I'd say you need to complete your user registration for your account poudyalrupak2@gmail.com before being able to send e-mails: https://sendgrid.com/docs/ui/account-and-settings/verifying-your-account/

Also, as a small improvement on your code, you should make any method which calls async methods async

public async Task Execute( string subject, string message, string email)

, and then await on any async calls:

return await client.SendEmailAsync(msg);
Peter Sandor
  • 143
  • 1
  • 7