Ana*_*put 0 node.js ecmascript-6 nodemailer template-strings
我正在尝试使用 nodemailer 从我的服务器发送电子邮件。不幸的是,由于这个错误,我一直无法对其进行测试:
D:\Full Stack\Node\NodeLoginJWT\functions\password.js:58
'This token is valid only within two minutes.'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected string
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (D:\Full Stack\Node\NodeLoginJWT\routes.js:9:18)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
[nodemon] app crashed - waiting for file changes before starting...
Run Code Online (Sandbox Code Playgroud)
这是导致错误的代码块:
const transporter = nodeMailer.createTransport(`smtps://${config.email}:${config.password}@smtp.gmail.com`);
const mailOptions = {
from: `"${conifg.name}" <${config.email}>`,
to: email,
subject: 'Reset Password',
html: `Hello ${user.name}`,
'Your account password token is ${random}'
'This token is valid only within two minutes.'
'Thanks,'
'Team. '
};
return transporter.sendMail(mailOptions);
Run Code Online (Sandbox Code Playgroud)
我正在使用 Nodemailer,这是我的代码:
\n\nvar express = require(\'express\');\nvar router = express.Router();\nvar nodemailer = require(\'nodemailer\');\n\nrouter.post(\'/\', handleSendEmail); // handle the route at yourdomain.com/sayHello\n\nfunction handleSendEmail(req, res) {\n // Not the movie transporter!\n var transporter = nodemailer.createTransport({\n service: \'Gmail\',\n auth: {\n user: \'\', // Your email id\n pass: \xe2\x80\x98\xe2\x80\x99// Your password\n }\n });\n var text = \'Hello from \\n\\n\' + req.body.user_name;\n var mailOptions = {\n from: \'sender@gmail.com\', // sender address\n to: \'receiver@gmail.com\', // list of receivers\n subject: \'Appointment Email Example\', // Subject line\n text: text,\n html: \'<!DOCTYPE html>\'+\n \'<html><head><title>Appointment</title>\'+\n \'</head><body><div>\'+\n \'<img src="http://evokebeautysalon1.herokuapp.com/main/img/logo.png" alt="" width="160">\'+\n \'<p>Thank you for your appointment.</p>\'+\n \'<p>Here is summery:</p>\'+\n \'<p>Name: James Falcon</p>\'+\n \'<p>Date: Feb 2, 2017</p>\'+\n \'<p>Package: Hair Cut </p>\'+\n \'<p>Arrival time: 4:30 PM</p>\'+\n \'</div></body></html>\'\n };\n transporter.sendMail(mailOptions, function(error, info){\n if(error){\n console.log(error);\n res.json({yo: \'error\'});\n }else{\n console.log(\'Message sent: \' + info.response);\n res.json({yo: info.response});\n };\n });\n}\n\nmodule.exports = router;\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
8925 次 |
| 最近记录: |