我有一个非常简单的应用程序,刚刚开始使用 nodemailer。当我运行应用程序时,模块本身出现错误。
app.js:
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport('smtps://me%40gmail.com:supersecretpw@smtp.gmail.com');
var mailOptions = {
from: '"Me" <me@gmail.com>', // sender address
to: 'him@him.com, her@her.com', // list of receivers
subject: 'Hello dude', // Subject line
text: 'Test email with text', // plaintext body
html: "Testing 1..2..7" // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
我得到这个错误:
C:\Users\Andrew\desktop\messy4\node_modules\nodemailer\lib\mailer\index.js:31
compile: [(...args) => this._convertDataImages(...args)],
^^^
SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (C:\Users\Andrew\desktop\messy4\node_modules\nodemailer\lib\nodemailer.js:3:16)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
真的不知道这里发生了什么。
最佳答案
需要 Node.js 版本 6+。使用以下命令检查您的 Node 版本:
Node --版本
如果您未满 6 岁,则必须升级。
您可能会收到另一条错误消息,指示您登录自己的帐户。在这种情况下,请转到您的电子邮件收件箱,您会看到来自 Google 的一条消息,其中包含指向用于设置安全性较低的应用权限的页面的链接。
关于javascript - Nodemailer 错误无法修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42045637/