Home
Support Forums

Sendgrid not sending

I can run a function locally using SendGrid API, using key. Works fine, sends me my email I construct.

Push it to Netlify, all working apart from the email(s) never arrive. Am I missing something? Have put debugs into the console so I can see things going on.

Any ideas?

I even printed out the SendGrid object and its all good. Its like its just failing to send.

ailService {
  client:
   Client {
     auth:
      'Bearer XXXXXXX',
     impersonateSubuser: '',
     defaultHeaders:
      { Accept: 'application/json',
        'Content-Type': 'application/json',
        'User-Agent': 'sendgrid/7.4.3;nodejs' },
     defaultRequest:
      { baseUrl: 'https://api.sendgrid.com/',
        url: '',
        method: 'GET',
        headers: {},
        maxContentLength: Infinity,
        maxBodyLength: Infinity } },
  substitutionWrappers: [ '{{', '}}' ],
  secretRules: [],
  MailService: [Function: MailService] }

Right, I’ve managed to get an error

5:00:35 PM: 3694b41e ERROR  ResponseError: Unauthorized
    at src/sendgrid.js:3449:29
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  code: 401,
  response: {
    headers: {
      server: 'nginx',
      date: 'Tue, 01 Jun 2021 16:00:35 GMT',
      'content-type': 'application/json',
      'content-length': '97',
      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',
      'strict-transport-security': 'max-age=600; includeSubDomains'
    },
    body: { errors: [Array] }
  }
}

This is from the Netlify log. Running locally still works fine.

So I think I needed to add an IP to the IP Access Management screen in SendGrid. Once I do that it works as expected (via browser and Postman)

1 Like

Hey there, @edhenderson :wave:

Welcome to the Netlify Forums! Thanks so much for updating us with your solution. This will be useful to any future Forums members who encounter something similar.

1 Like