我一直在尝试通过Windows控制台上的nodeJs通过sendgrid发送电子邮件。我尝试使用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();
我知道这已经很晚了,但是您需要发送信息:更改sgMail.send()
至sgMail.send(msg)
。
在nativescript js上有相同的错误。