[英]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.