TypeError: Cannot read property 'isMultiple' of undefined (using sendgrid, over nodejs on windows console)

Viewed 1083

I have been trying to send emails through sendgrid with nodeJs on the windows console. I tried to install it using the sendgrid tutorial :

echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env

when I enter "source ./sendgrid.env", the windows console doesn't recognize the command. Afterwards, I tried to use the setx command instead and now the console is giving this error log:

(node:23300) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'isMultiple' of undefined
    at MailService.send (E:\Escritorio\chuschusss\node_modules\@sendgrid\mail\src\classes\mail-service.js:86:23)
    at Object.<anonymous> (E:\Escritorio\chuschusss\index.js:12:8)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
(node:23300) 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)
(node:23300) [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.

code snippet used:

// using SendGrid's v3 Node.js Library
// https://github.com/sendgrid/sendgrid-nodejs
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: '***@gmail.com',
  from: '***@gmail.com',
  subject: 'Sending with SendGrid is Fun',
  text: 'and easy to do anywhere, even with Node.js',
  html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sgMail.send();

1 Answers

I know this is pretty late, but you need to send your message: change sgMail.send() to sgMail.send(msg).

Related