是否可以在同一路径中放置两个邮件选项?每次我尝试发送两个邮件时,它只发送一个邮件...我不想创建另一条路由,因为当新联系人填写表格时,两个邮件都必须发送。如果有人知道答案,我将不胜感激!这是我要尝试的路线:
router.post('/contact', function(req, res, next) {
var newContact = new contactModel({
contactName: req.body.firstName,
contactEmail: req.body.contactEmail,
contactPhone: req.body.contactPhone,
contactMessage: req.body.contactMessage,
contactNews: req.body.contactNews
});
newContact.save(
function(error, contact){
mongoose.model('contacts').find(
function(err, contact){
req.session.contact = contact;
res.render('index', {contact, isLoggedIn});
})
})
contactModel.find(
{
_id: req.body._id
},
function(err, contact) {
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'xxxx@gmail.com',
pass: 'xxxx'
}
});
var mailOptions =
{
from: 'xxx@gmail.com',
to: req.body.contactEmail,
subject: 'Contact xxx',
html: emailContent + emailContentParagraph + emailContentTwo +
emailContentThree + emailContentFour,
attachments: [
{
filename: 'image-mail.png',
path: './public/images/image-mail.png',
cid: 'imageOne'
},
{
filename: 'logo-header.png',
path: './public/images/logo-header.png',
cid: 'imageTwo'
},
]
};
var mailOptions = {
from: req.body.contactEmail,
to: 'xxx@gmail.com',
subject: 'Contact xxx',
html: req.body.contactName + req.body.contactMessage
};
transporter.sendMail(mailOptions, function(error, contact) {
if (error) {
console.log(error);
res.render('contact',{isLoggedIn});
} else {
}
});
});
});