sendgrid-nodejs: 403 Forbidden error sending simple email
Getting a 403 Forbidden error on sending a simple email via my Node project. Simply following the official integration guide. My API Key has full access. The code integration is correct as I have used an API Key from another account and it works perfectly. It is only with a particular account that this issue is present.
Exception/Log
ResponseError: Forbidden
at Request._callback (node_modules/@sendgrid/client/src/classes/client.js:124:25)
at Request.self.callback (node_modules/request/request.js:185:22)
at Request.emit (events.js:311:20)
at Request.EventEmitter.emit (domain.js:482:12)
at Request.<anonymous> (node_modules/request/request.js:1154:10)
at Request.emit (events.js:311:20)
at Request.EventEmitter.emit (domain.js:482:12)
at IncomingMessage.<anonymous> (node_modules/request/request.js:1076:12)
at Object.onceWrapper (events.js:417:28)
at IncomingMessage.emit (events.js:323:22)
at IncomingMessage.EventEmitter.emit (domain.js:482:12)
at endReadableNT (_stream_readable.js:1204:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 403,
message: 'Forbidden',
response: {
headers: {
server: 'nginx',
date: 'Sat, 11 Apr 2020 08:16:23 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'
},
body: { errors: [Array] }
}
}
- sendgrid-nodejs version: 6.5.5
- node version: 12.16.1
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 24 (6 by maintainers)
Hi @prolok , 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 from ANY email specified. Not sure what the real issue is.
I hope this solves the issue.
@childish-sambino I ran into this problem while trying to get through the sendgrid onboarding (https://app.sendgrid.com/guide/integrate/langs/nodejs). The problem for me was that I was using single sender verification to get started but the guide did not specify that the to field had to match the single sender address.
I see your quickstart does mention to change the from field but it would have been helpful to have emphasized this more throughout the onboarding. (especially as the onboarding says single sender auth is best suited for testing)
Maybe this is obvious to people with more domain knowledge about this but when I’ve used other stmp email services, the from field never had to match anything for the email to be delivered
Double-check if you are using the correct email address in “From”. This can also give you a “Forbidden” status code.
@prolok Try logging the error response body to get more details about what’s going on. Example here: https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/success-failure-errors.md
I’ve tried upgrading my account to a paid plan - didn’t work. I’ve also tried setting up Sender Authentication - and couldn’t get through it, even though I’ve added the DNS Records, and waited 48 hours for the DNS to populate. Tried to do the Sender Authentication with DNS provider=Cloudflare
When I try to add users to a contact list, or even as a general contact, it returns: ‘403 forbidden’
@childish-sambino below is my pm2 log when calling the function I copied from the integration guide and the function is triggered by a simple GET method in express js.
how can I get the
error.response.bodyyou mentioned? I think theerroris not getting from any part of my code (at least cannot captured from try catch), could you tell me how can I getting the error body while I am callingsgMail.send?The OP’s log does not include the full response body which has additional details. E.g.,
console.error(error.response.body)en mi caso era la direccion de correo del from por eso me generaba el error
There’s an example here of calling
sgMail.sendand catching/logging the error response and body.