[英]nodemailer mail options from: field is always sending mail from the email used in the smtpTrans auth object
[英]sending mail with nodemailer - email from field incorrect
尝试使用nodemailer设置联系表单。 这是我的app.js中的内容:
// 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而不是我在模板上输入电子邮件字段的电子邮件。 有任何想法吗
Gmail和许多其他电子邮件服务不允许您发送包含各种FROM
字段的邮件。
你可以使用邮戳,它们提供了一个很好的api来发送电子邮件,并且有一个节点模块( https://npmjs.org/package/postmark )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.