30

I am sending a very straightforward email using Send grid in my node js project. But I get returned a 403 Forbidden error. The API Key has full access. The code is also correctly integrated, as I used another API Key from another account and it works perfectly.

Error log:

enter image description here

Any suggestions?

iqra
  • 1,061
  • 1
  • 11
  • 18
  • facing the same problem - I see the x-no-cors-reason header has a link to their docs, https://sendgrid.com/docs/for-developers/sending-email/cors/, but it just says you cant use the sg api from the browser (duh) – Alfred Young May 08 '20 at 20:32
  • 1
    @AlfredYoung performing single Single Sender Authentication' on your Sendgrid account, solves this issue. – iqra May 13 '20 at 19:28

8 Answers8

46

The error exists as the email address in the "from" field in the message(in your nodejs code,, to be sent using sendgrid) is not verified by sendgrid. Only put that email address in the "from" field which is explicitely verified by sendgrid.

To verify your sender email address to be able to send emails, refer to the link below:-

https://sendgrid.com/docs/ui/sending-email/sender-verification

Hope this helps.

(There could be further issues regarding domain name, read the link properly, they have a warning regarding use of gmail.com addresses, you can ignore that)

Aman Chawla
  • 710
  • 6
  • 8
  • 6
    This should be the accepted answer, thank you! – Ahmad Alfy Apr 16 '21 at 01:34
  • How do you verify a "donotreply" email address, when the SendGrid wants to send a verificication email to an address that doesn't exist? – Oliver Nilsen Jul 07 '21 at 12:06
  • I'm not sure that I can use this particular field for this pourpose, and forgive me if its not, but thank you so much! I was thinking it was about the encoding method I was using in the fields passed by the class... – user3050478 Sep 27 '21 at 03:38
  • This solve my issue. Unfortunately, the API response doesn't give any details. – elier Mar 08 '23 at 16:18
8

Pasting the entire ERROR here

ResponseError: Forbidden
    at node_modules/@sendgrid/client/src/classes/client.js:133:29
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  code: 403,
  response: {
    headers: {
      server: 'nginx',
      date: 'Sat, 10 Oct 2020 17:22:02 GMT',
      'content-type': 'application/json',
      'content-length': '281',
      connection: 'close',
      'access-control-allow-origin': 'https://sendgrid.api-docs.io',
      'access-control-allow-methods': 'POST',
      'access-control-allow-headers': 'Authorization, Content-Type, On-behalf-of, x-sg-elas-acl',
      'access-control-max-age': '600',
      'x-no-cors-reason': 'https://sendgrid.com/docs/Classroom/Basics/API/cors.html'
    },

Here is the solution to further expand on what @Aman answered above.

  • You have to verify the email address you are sending from.

so meaning the from: address here

const msg = {
    to: 'recepient@email.com',
    from: 'sender@email.com', //this is the address that needs to be verified by sendgrid
    subject: 'Sending from Sendgrid',
    text: 'here is the test from node',
    html: `<strong> Here is the order #${orderNumber} user: ${user} </strong>`,
}

Here is how to verify it https://sendgrid.com/docs/ui/sending-email/sender-verification/

See screenshot below:

enter image description here

Jonathan Sanchez
  • 7,316
  • 1
  • 24
  • 20
5

Check whether from email address is used when you are verifying your send address.

3

I was having the same problem.
I discovered that the emails from of my application and the sender authentication of the SendGrid API need to be the same.

const sendMailHtml = async (subject, html) => {
    try {
        const msg = {
            to: 'to@email.com',
            from: {
                email: "sample@hotmail.com"
            },
            subject: subject,
            html: html,
        }
        await sendgrid.send(msg)
    } catch (e) {
        return e
    }
}

sendgrid API email field

enter image description here

Alexandre Neukirchen
  • 2,713
  • 7
  • 26
  • 36
  • 2
    This solved my problem - thanks! Kept getting 403 despite having a verified sender on SendGrid. No idea why the example show: "from: 'string'" instead of what you suggested. – Perelan Mar 13 '22 at 17:36
2

To fix this error you need go to perform SendGrid Sender Authentication for your sender email.

To do this, You need to login to your SendGrid Dashboard and visit Sender Authentication which is under the Settings dropdown.

There are 2 Types of Sender Authentication

  1. Domain Authentication // recommended
  2. Single Sender Verification

1 Domain Authentication
IF you allow SendGrid to authenticate your domain e.g. webapp.com
THEN you will be able to successfully send an email with your SendGrid API KEY if the email from key matches the verified domain from: *@webapp.com

2 Single Sender Authentication
This is another option where you verify a single email e.g. person@email.com.
Which will then allow you to send out emails from: person@email.com via your SendGrid API KEY

Tunji Oyeniran
  • 3,948
  • 1
  • 18
  • 16
0

In the latest release of sendgrid they have made the compulsion to verify the "Single Sender" i.e you as a single sender. So, to make it work the From field in your Sendgrid Send Email API should match the email you verified as a "single sender"

Amirhossein Mehrvarzi
  • 18,024
  • 7
  • 45
  • 70
0

verify your single sender account where Sender Authentication/Single Sender Verification/ action column (three-dot)(send verify email- edit -delete menu)

-3

[Tulio Faria] solved it by performing 'Single Sender Authentication' on his Sendgrid account.

I also had a similar issue not too long ago. What helped me fix this issue was to go to settings > API keys and then change the settings of the key I'm using to full-access. enter image description here

Sean C
  • 45
  • 1
  • 7
  • I'm facing the same problem. Changing the api key to full access does not solve it either. – Tulio Faria Apr 12 '20 at 15:10
  • 1
    Tulio Faria i solved it by performing 'Single Sender Authentication' on my Sendgrid account. However, I have another account and I have not verified any domain or sender email, but I am still able to send an email from that account. And its mind boggling because I can specify ANY email address as the sender and the email is successfully delivered. Not sure what the real issue is. – iqra Apr 14 '20 at 09:17
  • @Sean C and "aledap" I tried with same to change access but still facing the same issue, it will give me 403 error. – Codebrekers Sep 10 '20 at 05:38
  • 2
    @sean - this solution is overkill for what's really happening here, the error is because the `from: 'emailAddress@email.com',` inside your msg object has not been confirmed/verified by Sendgrid just yet – Jonathan Sanchez Oct 10 '20 at 17:29