Vazha
Vazha

Reputation: 33

Sendgrid API returns Forbidden C#

I am doing everything as it is shown in sendgrid's documentation

    var client = new SendGridClient(apiKey);
    var from = new EmailAddress("[email protected]", "Example User");
    var subject = "Sending with SendGrid is Fun";
    var to = new EmailAddress("[email protected]", "Example User");
    var plainTextContent = "and easy to do anywhere, even with C#";
    var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
    var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
    var response = await client.SendEmailAsync(msg);
    Console.WriteLine(response.StatusCode);

enter image description here

Upvotes: 0

Views: 556

Answers (1)

Vazha
Vazha

Reputation: 33

'From' mail should be registered in SendGrid as a verified sender. Settings -> Sender Authentication.

Upvotes: 1

Related Questions