【发布时间】:2016-06-13 13:43:17
【问题描述】:
我想通过 nodemailer 将 pdf 报告附加到邮件给用户。我在前端使用 jquery。
<script>
$(document).ready(function () {
var from, to, subject, text;
$("#send_email").click(function () {
to = $("#to").val();
subject = $("#subject").val();
text = $("#content").val();
$("#message").text("Sending E-mail...");
$.get("http://localhost:8080/send", {to: to, subject: subject, text: text}, function (data) {
if (data == "sent") {
$("#message").empty().html("Email is sent " + to + " .");
}
});
});
});
</script>
API 看起来像这样。它工作正常。我想知道如何动态添加附件
app.get('/send', function (req, res) {
var mailOptions = {
to: req.query.to,
subject: req.query.subject,
text: req.query.text
};
console.log(mailOptions);
smtpTransport.sendMail(mailOptions, function (error, response) {
if (error) {
console.log(error);
res.end("error");
}
else {
console.log("Message sent: " + response.message);
res.end("sent");
}
});
});
【问题讨论】:
标签: jquery node.js pdf mean-stack nodemailer