node.js - 使用 nodemailer 发送邮件 - 来自字段的电子邮件不正确

标签 node.js express pug nodemailer

尝试使用 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

电子邮件现在有效,但来 self 的电子邮件地址,而不是我在模板的电子邮件字段中输入的地址。任何想法

最佳答案

Gmail 和许多其他电子邮件服务不允许您发送带有各种FROM 字段的邮件。

关于node.js - 使用 nodemailer 发送邮件 - 来自字段的电子邮件不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16943961/

相关文章:

javascript - Express JS - 从 mysql 删除条目

node.js - NodeJS url请求,绝对还是相对?

javascript - 在从对 AWS Secrets Manager 的 API 调用返回数据后导出 Node 文件中的数据

node.js - 如何使用 mongo/mongoose 连接远程数据库

javascript - 来自 Jade 模板的 Handlebars 条件检查属性

node.js - 如何定义用于 Backbone 的 jade 模板

javascript - Node.js Socket.io 错误 : disconnect event is triggered after connect

mysql - nodejs连接mysql报错

javascript - 何时关闭 MongoDB 连接

pug - Sails 中 csrf token 的 Jade 等价物