Nodemailer 错误无法修复
Nodemailer Error Can't Fix
我有一个非常简单的应用程序,刚开始接触 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
如果您未满 6 岁,则必须升级。
您可能会收到另一条错误消息,指示您登录您的帐户。在这种情况下,请转到您的电子邮件收件箱,您会看到一条来自 Google 的消息,带有 link 到用于设置安全性较低的应用程序权限的页面。
只需将其添加到您的 package.json 文件中。
"engines": {
"node": "6.9.4" // You can use any version
}
这将自动下载您提供的节点版本。通过这种方式,您不需要每次都在服务器上升级您的 NodeJS。
Nodemailer 兼容 Node 版本 6 或更高版本(根据 https://nodemailer.com/about/#requirements)
因此请按照以下步骤升级节点:
1* sudo npm 缓存清理 -f
2* sudo npm install -g n
3* sudo n 稳定
4* sudo ln -sf /usr/local/n/versions/node/5.4.1/bin/node /usr/bin/node (粗体text/version 应该是在上述步骤中安装的那个。)
即如果安装了 8.1.1 则执行 sudo ln -sf /usr/local/n/versions/node/8.1.1/bin/node /usr/bin/node
node –v(现在应该显示更新版本)
这里也有回答
我有一个非常简单的应用程序,刚开始接触 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
如果您未满 6 岁,则必须升级。
您可能会收到另一条错误消息,指示您登录您的帐户。在这种情况下,请转到您的电子邮件收件箱,您会看到一条来自 Google 的消息,带有 link 到用于设置安全性较低的应用程序权限的页面。
只需将其添加到您的 package.json 文件中。
"engines": {
"node": "6.9.4" // You can use any version
}
这将自动下载您提供的节点版本。通过这种方式,您不需要每次都在服务器上升级您的 NodeJS。
Nodemailer 兼容 Node 版本 6 或更高版本(根据 https://nodemailer.com/about/#requirements)
因此请按照以下步骤升级节点:
1* sudo npm 缓存清理 -f
2* sudo npm install -g n
3* sudo n 稳定
4* sudo ln -sf /usr/local/n/versions/node/5.4.1/bin/node /usr/bin/node (粗体text/version 应该是在上述步骤中安装的那个。)
即如果安装了 8.1.1 则执行 sudo ln -sf /usr/local/n/versions/node/8.1.1/bin/node /usr/bin/node
node –v(现在应该显示更新版本)
这里也有回答