sendgrid-nodejs: unable to send mail

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

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

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