我写了一个nodemailer
函数,如下:-
app.post('/sendemail', (req, res) => {
const output = `
<p>You have a new contact request</p>
<h3>Contact Details</h3>
<ul> ;
<li>Name: ${req.body.name}</li>
<li>Email: ${req.body.email}</li>
<li>Phone: ${req.body.phone}</li>
</ul>
<h3>Message</h3>
<p>${req.body.message}</p>
`;
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
service: 'gmail ',
auth: {
user: 'atul.11192@gmail.com',
pass: 'xxxxxxxxx'
},
tls: {
rejectUnauthorized: false
}
});
// setup email data with unicode symbols
let mailOptions = {
from: '"Enquiry from datadock" <atul.11192@gmail.com>', // sender address
to: 'atul.11192@gmail.com', // list of receivers
subject: 'Datadock Enquiry ', // Subject line
text: 'Hello world?', // plain text body
html: output // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
res.render('contacthanks.ejs', {
message: 'Email has been sent'
});
});
});
现在成功之后,我想显示一个显示成功或错误的模式(或弹出窗口),谁能告诉我如何在模式中传递一些信息并显示成功或失败?
答案 0 :(得分:0)
您可以使用this question中的方法。所以你可以这样做
function doModal(heading, formContent, strSubmitFunc, btnText) {
var html = '<div id="modalWindow" class="modal hide fade in" style="display:none;">';
html += '<div class="modal-header">';
html += '<a class="close" data-dismiss="modal">×</a>';
html += '<h4>' + heading + '</h4>'
html += '</div>';
html += '<div class="modal-body">';
html += '<p>';
html += formContent;
html += '</div>';
html += '<div class="modal-footer">';
if (btnText != '') {
html += '<span class="btn btn-success"';
html += ' onClick="' + strSubmitFunc + '">' + btnText;
html += '</span>';
}
html += '<span class="btn" data-dismiss="modal">';
html += 'Close';
html += '</span>'; // close button
html += '</div>'; // footer
html += '</div>'; // modalWindow
$("body").html(html);
$("#modalWindow").modal();
}
function hideModal() {
// Using a very general selector - this is because $('#modalDiv').hide
// will remove the modal window but not the mask
$('.modal.in').modal('hide');
}
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
doModal("Error", error, hideModal, "OK");
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
doModal("Message sent: " + info.messageId, "Preview URL: " + nodemailer.getTestMessageUrl(info), hideModal, "OK");
res.render('contacthanks.ejs', {
message: 'Email has been sent'
});
});