FullstackReactCode icon indicating copy to clipboard operation
FullstackReactCode copied to clipboard

UnhandledPromiseRejectionWarning: SendGridError: Response error ; Layman Fix

Open vinc3nati opened this issue 5 years ago • 5 comments

In the new version of sendgrid , we have to 1. Verify our account and 2. Single Sender Authentication . The mail which you specify in the Single Sender Authentication must be the same in the

.fromEmail attribute

We cannot specify an email unless it is genuine i.e. we cannot use '[email protected]' unless it is a verified email.

vinc3nati avatar Aug 20 '20 07:08 vinc3nati

Hey, can you provide the steps for the fix and what code have you used for it? I have to use the updated library right ie @sendgrid/mail and the email has to be single sender authentication should be used in the code as well right?

ganya7 avatar Aug 21 '20 17:08 ganya7

Hey, can you provide the steps for the fix and what code have you used for it? I have to use the updated library right ie @sendgrid/mail and the email has to be single sender authentication should be used in the code as well right?

I have created a temporary Email Id for sending emails and updated the same in both Sendgrid Sender Authentication and from field in our code. It works fine then :D

vinc3nati avatar Aug 31 '20 13:08 vinc3nati

yeah I was able to get it work. Anyone who is still facing the issue here is the way it worked for me: you have to download and use the new sengrid library: @sendgrid/mail ie npm install and save it in package.json you have to do the sendgrid single sender authentication step which is going to be your "from" email and use the following code:

Mailer.js

const keys = require('../config/keys');
const sgMail = require('@sendgrid/mail');

module.exports = async ({ subject, recipients }, content) => {
  // using SendGrid's v3 Node.js Library
  // https://github.com/sendgrid/sendgrid-nodejs
  sgMail.setApiKey(keys.sendGridKey);
  const formattedRecipients = recipients.map(({email}) => email);
  const msg = {
    to: formattedRecipients,
    from: '[email protected]',
    subject: subject,
    html: content,
  };
  return await sgMail.send(msg);
}

surveyRoutes.js

const m = Mailer(survey, surveyTemplate(survey));

ganya7 avatar Sep 06 '20 21:09 ganya7

Remember while testing it out, on the dev tools console you might get an error like:

xhr.js:178 POST http://localhost:3000/api/surveys net::ERR_EMPTY_RESPONSE createError.js:16 Uncaught (in promise) Error: Network Error at createError (createError.js:16) at XMLHttpRequest.handleError (xhr.js:83)

this is fine as I guess we haven't handled the response yet at that point of time in the video. But check your to email and I found it in my spam folder

ganya7 avatar Sep 06 '20 21:09 ganya7

SendGrid has now made it hard to open an account. I have tried multiple times to send multiple emails to the support team which they made necessary to and I still can't open an account. they require a whole bunch of information about your business and all the other kind of information which we don't have at this point (assuming you are following the course). so now I am using an alternative to SendGrid. it's similar in most cases. its name is Sendinblue. I would suggest if you are unable to open an account on send grid use send in blue. read the documentation and if you still need help setting it up https://github.com/sendinblue/APIv3-nodejs-library follow the link up there and you are good to go.

zeeshanejaz786 avatar Jan 20 '22 11:01 zeeshanejaz786