TypeError: Невозможно прочитать свойство 'isMultiple' из неопределенного (с использованием sendgrid, поверх nodejs на консоли Windows) - PullRequest
0 голосов
/ 17 декабря 2018

Я пытался отправить электронную почту через sendgrid с помощью nodeJs на консоли Windows.Я попытался установить его с помощью руководства по sendgrid:

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

при вводе «source ./sendgrid.env» консоль Windows не распознает команду.После этого я попытался использовать команду setx, и теперь консоль выдает этот журнал ошибок:

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

Используемый фрагмент кода:

// 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 Ответ

0 голосов
/ 20 февраля 2019

Я знаю, что уже довольно поздно, но вам нужно отправить сообщение: измените sgMail.send() на sgMail.send(msg).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...