gpt4 book ai didi

node.js - 使用 Nodejs 和 HTML 正文发送邮件

转载 作者:太空宇宙 更新时间:2023-11-04 03:23:20 25 4
gpt4 key购买 nike

我正在尝试使用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...

这是导致错误的代码块:

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);

最佳答案

我正在使用 Nodemailer,这是我的代码:

var express = require('express');
var router = express.Router();
var nodemailer = require('nodemailer');

router.post('/', handleSendEmail); // handle the route at yourdomain.com/sayHello

function handleSendEmail(req, res) {
// Not the movie transporter!
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: '', // Your email id
pass: ‘’// Your password
}
});
var text = 'Hello from \n\n' + req.body.user_name;
var mailOptions = {
from: 'sender@gmail.com', // sender address
to: 'receiver@gmail.com', // list of receivers
subject: 'Appointment Email Example', // Subject line
text: text,
html: '<!DOCTYPE html>'+
'<html><head><title>Appointment</title>'+
'</head><body><div>'+
'<img src="http://evokebeautysalon1.herokuapp.com/main/img/logo.png" alt="" width="160">'+
'<p>Thank you for your appointment.</p>'+
'<p>Here is summery:</p>'+
'<p>Name: James Falcon</p>'+
'<p>Date: Feb 2, 2017</p>'+
'<p>Package: Hair Cut </p>'+
'<p>Arrival time: 4:30 PM</p>'+
'</div></body></html>'
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
res.json({yo: 'error'});
}else{
console.log('Message sent: ' + info.response);
res.json({yo: info.response});
};
});
}

module.exports = router;

关于node.js - 使用 Nodejs 和 HTML 正文发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47736305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com