FullstackReactCode icon indicating copy to clipboard operation
FullstackReactCode copied to clipboard

UnhandledPromiseRejectionWarning: SendGridError: Response error - error when using axios to send fake survey

Open rostgoat opened this issue 6 years ago • 29 comments

image

stack trace

 (node:5628) UnhandledPromiseRejectionWarning: SendGridError: Response error
[0]     at c:\react_tut\server\node_modules\sendgrid\lib\sendgrid.js:104:23
[0]     at IncomingMessage.<anonymous> (c:\react_tut\server\node_modules\sendgrid-rest\lib\client.js:112:9)
[0]     at emitNone (events.js:111:20)
[0]     at IncomingMessage.emit (events.js:208:7)
[0]     at endReadableNT (_stream_readable.js:1064:12)
[0]     at _combinedTickCallback (internal/process/next_tick.js:138:11)
[0]     at process._tickCallback (internal/process/next_tick.js:180:9)
[0] (node:5628) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)

did anyone have this issue when trying to send the email through axios?

rostgoat avatar Jun 02 '18 18:06 rostgoat

@StephenGrider do you know why this might be an issue? you didn't seem to have this error in the tutorial and I double checked your code in the repo to make sure mine isnt missing anything

rostgoat avatar Jun 02 '18 18:06 rostgoat

looks like the error is thrown inside the try block in surveyRoutes, in the await mailer.send() line..

image

console:

image

removing await from that line allows me to see all the other console logs but the request still fails and throws a 422

rostgoat avatar Jun 03 '18 18:06 rostgoat

Hi, I'm hitting the exact same problem, unclear how to proceed. Thanks for any information that can be provided!

nitini avatar Jun 08 '18 05:06 nitini

Guys, check your code well and compare it with one in repository. Everything works fine, I got no-reply mail and updated MongoDb!!! You must have made typo somewhere!!!!

emirfer avatar Aug 05 '18 02:08 emirfer

Be careful! In Mailer.js, path:'v3/mail/send', NOT path:'V3/mail/send'

emirfer avatar Aug 05 '18 03:08 emirfer

@rostgoat @nitini In Mailer.js class please double check that the content variable is not wrapped inside of quotation marks You should have line like this this.body = new helper.Content('text/html', content) NOT like this this.body = new helper.Content('text/html, content')

Had a similar issue

Hope it helps!

aissayev avatar Aug 17 '18 22:08 aissayev

I got the same error. I forgot "await" in the const response. const response = await this.sgApi.API(request);

Marcol132 avatar Jan 17 '19 16:01 Marcol132

[0] (node:31420) UnhandledPromiseRejectionWarning: SendGridError: Response error [0] at F:\Web Development\MERN\Projects\Feedback\server\node_modules\sendgrid\lib\sendgrid.js:104:23 [0] at IncomingMessage.<anonymous> (F:\Web Development\MERN\Projects\Feedback\server\node_modules\sendgrid-rest\lib\client.js:112:9) [0] at IncomingMessage.emit (events.js:187:15) [0] at endReadableNT (_stream_readable.js:1094:12) [0] at process._tickCallback (internal/process/next_tick.js:63:19) [0] (node:31420) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) [0] (node:31420) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Getting the same error

NikhileshAS avatar May 05 '19 14:05 NikhileshAS

triplecheck the send() method in Mailer.js, he added the await there while in the tutorial, he didn't.

1512413-TrucGiaPhu avatar Jun 15 '19 16:06 1512413-TrucGiaPhu

I have an error Screenshot (244)

viso24-7 avatar Aug 16 '19 08:08 viso24-7

for the ones that don't want to spend much time on this and just continue, I leave my 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,
  };
  await sgMail.send(msg);
}

and then the call in surveyRouter

    Mailer(survey, surveyTemplate(survey));

ignj avatar Sep 30 '19 23:09 ignj

I'm getting same error .. any solution ?

MAfzalKhan1997 avatar Apr 23 '20 20:04 MAfzalKhan1997

Yes I am also getting same error.

harshthakur066 avatar May 16 '20 17:05 harshthakur066

for the ones that don't want to spend much time on this and just continue, I leave my 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,
  };
  await sgMail.send(msg);
}

and then the call in surveyRouter

    Mailer(survey, surveyTemplate(survey));

This doesn't worked for me. Sad

harshthakur066 avatar May 16 '20 17:05 harshthakur066

Hi ALL, I know this is tooo late haha but if someone reach to same problem, check the from: '[email protected]', should be the email you set in your sendgrid account! Hope that helps

matva92 avatar Jun 30 '20 03:06 matva92

for the ones that don't want to spend much time on this and just continue, I leave my 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,
  };
  await sgMail.send(msg);
}

and then the call in surveyRouter

    Mailer(survey, surveyTemplate(survey));

This doesn't worked for me. Sad

Check from: '[email protected]' - set it to the email you set in your sendgrid account!

matva92 avatar Jun 30 '20 03:06 matva92

SEND_GRID { [0] errors: [ [0] { [0] message: 'The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements', [0] field: 'from', [0] help: null [0] } [0] ]

You need to setup a Sender Identity, if you are using Free Trial and received access on or after April 6, 2020. For POCs its best to choose Single Sender Verification. More information here : https://sendgrid.com/docs/for-developers/sending-email/sender-identity/

ganeshyedla avatar Jul 04 '20 10:07 ganeshyedla

In Mailer.js at line this.from_email=new helper.Email('[email protected]'); You have to replace this email with the authorized one which you created on sendgrid website.

zuha-khalid-au3 avatar Jul 29 '20 13:07 zuha-khalid-au3

Hey I tried all of the methods but still getting this error, Please help @StephenGrider Here is my Mailer.js: https://drive.google.com/file/d/1uGvjVjwrfoa8MJKd81iVj0qWthbvQU_n/view?usp=sharing

client/src/index.js: https://drive.google.com/file/d/1yw47JKhbve1T8-7oaVuuui2fkHynKhlu/view?usp=sharing

surveyRoutes.js https://drive.google.com/file/d/1nts2u2Wzb-YEqesXNrk1IOvTIoPvMfDo/view?usp=sharing

Annotation 2020-08-19 202709

vinc3nati avatar Aug 19 '20 15:08 vinc3nati

SEND_GRID { [0] errors: [ [0] { [0] message: 'The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements', [0] field: 'from', [0] help: null [0] } [0] ]

You need to setup a Sender Identity, if you are using Free Trial and received access on or after April 6, 2020. For POCs its best to choose Single Sender Verification. More information here : https://sendgrid.com/docs/for-developers/sending-email/sender-identity/

Hey, What if we do not create both domain or single sender verification? Is this necessary to do the domain/single sender verification?

vinc3nati avatar Aug 19 '20 17:08 vinc3nati

Hi ALL, I know this is tooo late haha but if someone reach to same problem, check the from: '[email protected]', should be the email you set in your sendgrid account! Hope that helps

Thanks, this is what worked for me.

NickJoyce-IO avatar Aug 31 '20 15:08 NickJoyce-IO

this.from_email = new helper.Email("sender mail id");

you just have to use this in Mailer.js. And make sure that you are using same mail id which you have set as a sender mail id in sendgrid.

7NithinShetty avatar Mar 23 '21 14:03 7NithinShetty

To resolve the issue, I put const response = await this.sgApi.API(request); in a try-catch block. This would also help to reveal if there are other errors you made in your code.

image

OluwakemiFasae avatar Mar 25 '21 14:03 OluwakemiFasae

Since I'm in India I had to use INR instead of USD. it worked.

On Thu, 25 Mar 2021 at 20:26, OluwakemiFasae @.***> wrote:

To resolve the issue, I put const response = await this.sgApi.API(request); in a try-catch block. This would also help to reveal if there are other errors you made in your code.

[image: image] https://user-images.githubusercontent.com/11194167/112493082-23c04480-8d82-11eb-908e-19424383cdab.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/StephenGrider/FullstackReactCode/issues/30#issuecomment-806898306, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQIH66ULFAVSGT6JT3KQYILTFNFKPANCNFSM4FC7EFWA .

7NithinShetty avatar Apr 10 '21 13:04 7NithinShetty

Hii Stephen, But now I'm facing a different problem. It's been more than 15days i'm not able to solve this error. For the last 3weeks i'm asking you for help in udemy chat. But i didn't get any response from your side. Please help me out.

Problem: After i click on yes/no from my mail, i'm not getting anything in return to my console as in course. I have noticed that there is no activity there in the "activity feed" of sendgrid. Here is my repository: https://github.com/7NithinShetty/feedback_app Please help me out with this.

Thanks & Regards, Nithin Shetty

On Sat, 10 Apr 2021 at 19:22, Nithin Shetty @.***> wrote:

Since I'm in India I had to use INR instead of USD. it worked.

On Thu, 25 Mar 2021 at 20:26, OluwakemiFasae @.***> wrote:

To resolve the issue, I put const response = await this.sgApi.API(request); in a try-catch block. This would also help to reveal if there are other errors you made in your code.

[image: image] https://user-images.githubusercontent.com/11194167/112493082-23c04480-8d82-11eb-908e-19424383cdab.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/StephenGrider/FullstackReactCode/issues/30#issuecomment-806898306, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQIH66ULFAVSGT6JT3KQYILTFNFKPANCNFSM4FC7EFWA .

7NithinShetty avatar Apr 10 '21 13:04 7NithinShetty

I had this issue, my falut was forget to verify sender in sendgrid. Please remeber to verify the sender!!!

KeyanSong1998 avatar Jul 02 '21 04:07 KeyanSong1998

@StephenGrider do you know why this might be an issue? you didn't seem to have this error in the tutorial and I double checked your code in the repo to make sure mine isnt missing anything

I had this issue, my falut was forget to verify sender in sendgrid. Please remeber to verify the sender!!!

KeyanSong1998 avatar Jul 02 '21 04:07 KeyanSong1998

Grider used "sendgrid": "^5.1.2" which is now deprecated. Use "@sendgrid/mail" instead . Like this :

Mailer.js File

const keys = require("../config/keys");
const helper = require("@sendgrid/mail").setApiKey(keys.sendGridKey);

const Mailer = (survey, content) => {
  const { subject, recipients } = survey;

  const formatEmail = (emails) => {
    const total = [];
    emails.forEach((item) => {
      total.push(item.email);
    });
    return total;
  };

  const msg = {
    to: formatEmail(recipients),
    from: {
      name: "surveyApp.com",
      email: "Your Varified Email at sengrid",
    },
    subject,
    text: "hello",
    html: content,
  };

  helper.send(msg).then(
    (res) => {
      console.log("email sent", res);
    },
    (error) => {
      console.error(error);

      if (error.response) {
        console.error(error.response.body);
      }
    }
  );
};
module.exports = Mailer; 

surveyRoute.js Mailer(survey, surveyTemplate(survey));

Thats should or must work ._

darda-ergo avatar Jul 11 '21 06:07 darda-ergo

@darda-ergo thank you buddy! it worked out for me after i followed your code !

ybakhshi avatar Feb 28 '24 22:02 ybakhshi