试图设置与nodemailer的联系表单。下面是在我的app.js:用nodemailer发送邮件 - 来自现场的电子邮件不正确
// EMail configuration
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "myemailaddress",
pass: "xxx"
}
});
// CONTACT FORM
app.get('/contact', function (req, res) {
res.render("contact");
});
app.post('/contact', function (req, res) {
var mailOptions = {
from: req.body.email, // sender address
to: "myemailaddress", // list of receivers
subject: req.body.subject, // Subject line
text: req.body.message, // plaintext body
}
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
smtpTransport.close(); // shut down the connection pool, no more messages
});
res.render("contact", { success: "building web app" });
});
而且我contact.jade模板看起来是这样的:
form#contact-form(action="/contact", method="POST")
div.span5
p Full name:
input#name(type="text", name="name")
p Email address:
input#email(type="email", name="email")
p Subject:
input#subject(type="text", name="subject")
p Message:
textarea#message(type="text", name="message", rows="5")
p: button(type="submit") Send message
电子邮件现在的作品,而是来自myemailaddress而不是一个我进入电子邮件在模板上的字段。任何想法
啊节点模块,OK。所以我会把它放在消息文本的正文中。感谢那。 – babbaggeii
唯一可以修改的是发件人名称,所以'Joe Doe <[email protected]>''可能是'我的邮件服务<[email protected]>' – wachme
Thanks @wachme!我对使用电子邮件服务很陌生。你有一个允许这种定制的电子邮件提供商的短名单吗?亚马逊SES能够做到这一点吗?你可以分享原始文档或其他资源,指定gmail不这样做吗?谢谢! – Adam