Nodemailer错误无法修复

我有一个非常简单的应用程序,刚开始用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 --version

如果你不是至less6+,那么你必须升级。

您可能会收到另一个错误消息,指示您login到您的帐户。 在这种情况下,请转到您的电子邮件收件箱,然后您会看到Google提供的一条消息,指向设置不太安全的应用权限的页面链接。

只需将其添加到package.json文件中。

 "engines": { "node": "6.9.4" // You can use any version } 

这将自动下载您提供的节点版本。 通过这种方式,你不需要每次在服务器上升级你的NodeJS。

Nodemailer与Node 6或更高版本兼容(按照https://nodemailer.com/about/#requirements

因此,请按照以下步骤升级节点:

1 * sudo npm cache clean -f

2 * sudo npm install -gn

3 * sudo n稳定

4 * sudo ln -sf / usr / local / n / versions / node / 5.4.1 / bin / node / usr / bin / node (粗体文本/版本应该是以上步骤中安装的)。

即如果安装了8.1.1,则执行sudo ln -sf / usr / local / n / versions / node / 8.1.1 / bin / node / usr / bin / node

节点-v(现在应该显示更新的版本)

当需要的时候在这里回答以及Nodemailer错误