Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Status Forbidden -When Sending Email with Sendgrid

i am trying to send email through sendgrid. But every time it return status Forbidden.

 public Task SendEmailAsync(string email, string subject, string message)
    {
        var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        return Execute(apiKey, subject, message, email);
    }

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

        var client = new SendGridClient(apiKey);
        var from = new EmailAddress(Configuration["Email"], Configuration["Name"]);
        var to = new EmailAddress(email);

        var plainTextContent = message;
        var htmlContent =message;
        var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
        var response = await client.SendEmailAsync(msg);

    }
like image 923
Muhammad Sami Avatar asked Apr 10 '20 11:04

Muhammad Sami


1 Answers

I suspect that you have not registered a "from" email address. You will get a forbidden response when you try to send the email in their example, because the form address is not registered to their account. Assuming you've created a free account, log in and go to https://app.sendgrid.com/settings/sender_auth . In the middle of the page you'll see "Verify Single Sender". If you are just exploring things you can use your own email for this.

like image 62
GlennSills Avatar answered Oct 01 '22 15:10

GlennSills