StephenGrider / FullstackReactCode

Companion repo to https://www.udemy.com/node-with-react-fullstack-web-development
1.39k stars 1.17k forks source link

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

Open rostgoat opened 6 years ago

rostgoat commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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

nitini commented 6 years ago

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

emirfer commented 6 years ago

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 commented 6 years ago

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

aissayev commented 6 years ago

@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!

Marcol132 commented 5 years ago

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

NikhileshAS commented 5 years ago

[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

1512413-TrucGiaPhu commented 5 years ago

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

viso24-7 commented 5 years ago

I have an error Screenshot (244)

ignj commented 5 years ago

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: 'no-reply@emaily.com',
    subject: subject,
    html: content,
  };
  await sgMail.send(msg);
}

and then the call in surveyRouter

    Mailer(survey, surveyTemplate(survey));
MAfzalKhan1997 commented 4 years ago

I'm getting same error .. any solution ?

harshthakur066 commented 4 years ago

Yes I am also getting same error.

harshthakur066 commented 4 years ago

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: 'no-reply@emaily.com',
    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

matva92 commented 4 years ago

Hi ALL, I know this is tooo late haha but if someone reach to same problem, check the from: 'no-reply@emaily.com', should be the email you set in your sendgrid account! Hope that helps

matva92 commented 4 years ago

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: 'no-reply@emaily.com',
    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: 'no-reply@emaily.com' - set it to the email you set in your sendgrid account!

ganeshyedla commented 4 years ago

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/

zuha-khalid-au3 commented 4 years ago

In Mailer.js at line this.from_email=new helper.Email('no-reply@emaily.com'); You have to replace this email with the authorized one which you created on sendgrid website.

vinc3nati commented 4 years ago

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 commented 4 years ago

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?

NickJoyce-IO commented 4 years ago

Hi ALL, I know this is tooo late haha but if someone reach to same problem, check the from: 'no-reply@emaily.com', should be the email you set in your sendgrid account! Hope that helps

Thanks, this is what worked for me.

7NithinShetty commented 3 years ago
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.

OluwakemiFasae commented 3 years ago

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

7NithinShetty commented 3 years ago

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 commented 3 years ago

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 .

KeyanSong1998 commented 3 years ago

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

KeyanSong1998 commented 3 years ago

@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!!!

darda-ergo commented 3 years ago

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 .__

ybakhshi commented 9 months ago

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