Sendgrid-nodejs: unable to send mail

Created on 15 Dec 2017  ·  17Comments  ·  Source: sendgrid/sendgrid-nodejs

Issue Summary

*SUPPORT DIRECTED ME HERE *
PROOF: https://support.sendgrid.com/hc/en-us/requests/1325416?page=1

I am unable to send email with the library. support directed me here. I am attempting to send from node.js, running on localhost. i first tried the example as listed on npm, but i get a 401 error with an header that is like x-no-cors reason. so i tried to use @sendgrid/mail package instead, and with that i get an error that says this:

TypeError: Cannot read property 'errors' of undefined
at ResponseError.toString (E:\songsplits\api\node_modules\@sendgrid\helpers\classes\response-error.js:45:27)
at Function.CapturedTrace.parseStackAndMessage (E:\songsplits\api\node_modules\bluebird\js\main\captured_trace.js:176:25)
at CapturedTrace.attachExtraTrace (E:\songsplits\api\node_modules\bluebird\js\main\captured_trace.js:79:32)
at Promise._attachExtraTrace (E:\songsplits\api\node_modules\bluebird\js\main\debuggability.js:102:19)
at Promise._rejectCallback (E:\songsplits\api\node_modules\bluebird\js\main\promise.js:471:10)
at E:\songsplits\api\node_modules\bluebird\js\main\promise.js:486:17
at Request.http [as _callback] (E:\songsplits\api\node_modules\@sendgrid\client\src\client.js:124:18)
at Request.self.callback (E:\songsplits\api\node_modules\request\request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (E:\songsplits\api\node_modules\request\request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage.<anonymous> (E:\songsplits\api\node_modules\request\request.js:1091:12)
at IncomingMessage.g (events.js:291:16)
at emitNone (events.js:91:20)

Steps to Reproduce

here is a minimal module to reproduce

email.js


const sgMail = require('@sendgrid/mail')

sgMail.setApiKey(process.env.SENDGRID_KEY);

module.exports.send = function send(html,subject,to,from){

    return new Promise((resolve,reject)=>{

        sgMail.send({
            to,
            from,
            subject,
            html
        }).then(resolve).catch(reject);

    });
};

index.js

const send = require('./mail');

send(
    '<!DOCTYPE html><html><head><title>Hi</title></head><body>Hi</body></html>',
    'Hi',
    'recipient@example.com',
    'sender@example.com',
).then(()=>console.log('sent an email successfully!')).catch(err=>console.log(err));

Technical details:

  • sendgrid-nodejs Version: master (latest commit: [commit number])
  • Node.js Version: 6
help wanted question

All 17 comments

just tried with another key too, and no bueno. sometimes, the error doesn't occur, and then the response is

Unauthorized (401)
Permission denied, wrong credentials

Hi @r3wt,

This is an issue our support team can help with. They can help dig into your account to figure out the issue with your key(s).

Thank you!

With Best Regards,

Elmer

@thinkingserious Your support team is the one who directed me here.

@r3wt

I know that this can happen if you publish your API Key to github, because our compliance team will disable your key.

The other thing that can happen is if you have IP management turned on, where your account is only accessible from specific IPs. If your code is running on an IP that is not in that list, it will cause errors as well.

Can you please do me a favor and create a new API key with mail/send priviledges and try the code again?

While you are doing that, can you please tell us your support ticket number?
Thanks!!

I see the ticket now... so I will look there too. THanks!

@mbernier the key is in a config file on a private repo. how would your team be able to detect this? there is no danger of the key leaking, it is a private repository.

now, some info about my connection:

  • satellite, ipv6. no remote inbound connections.
  • i am running the app on localhost

So if it's private, then that isn't an issue - although our InfoSec teams always suggest not putting keys even in private repos :)

Your app should be able to send the emails.

Can you please go here: https://sendgrid.com/docs/API_Reference/api_v3.html and try sending through the "Try it" tab on that docs page? If you get an error back, please post the response and error here.

@mbernier

image

@mbernier unfortunately errors still occurring in node.js

image

It looks like your account is not activated. Can you please login at app.sendgrid.com and look for the notifications at the top of the page. It will direct you to give a little more information about yourself, in order to prove that you are a good sender.

@mbernier my clients account has been active for atleast 2 years. i checked the logs and the client is actively sending other email campaigns and stuff? i'm confused.

@mbernier after i followed the setup instructions from the interactive account menu, it worked. so bizarre.

Sorry about that, I am not sure what could have happened. I made notes on the support ticket, so my hope is that with their access they can give us more details.

I am glad it's working now!

@r3wt I am going to close this, please let us know if you run into any other issues!

@mbernier the issue is happening again.

Hello @r3wt,

Could you please reach back out to our support team, via the original support ticket you opened with them, and link to this thread? I'm thinking something may have happened to your account and they have the tools to investigate your account.

Thanks!

With Best Regards,

Elmer

Just letting you know, I had very similar issues as far as I can tell (still new). The solution was to setup API key variable in app platform heroku https://devcenter.heroku.com/articles/sendgrid#setup-api-key-environment-variable
No problems now for me.

Was this page helpful?
0 / 5 - 0 ratings