【问题标题】:sending mail with nodemailer - email from field incorrect使用 nodemailer 发送邮件 - 来自字段的电子邮件不正确
【发布时间】:2013-06-01 09:23:29
【问题描述】:

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

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

【问题讨论】:

    标签: node.js express pug nodemailer


    【解决方案1】:

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

    【讨论】:

    • 啊,好的。所以我会把它放在消息文本的正文中。谢谢你。
    • 唯一可以修改的是发件人的名字,所以Joe Doe <myemailaddress@gmail.com>可能是My mailing service <myemailaddress@gmail.com>
    • 谢谢@wachme!我对使用电子邮件服务很陌生。您是否有允许此自定义的电子邮件提供商的简短列表? Amazon SES 能做到这一点吗?你能分享原始文档或其他指定gmail不这样做的资源吗?谢谢!
    【解决方案2】:

    你可以使用邮戳,他们提供了一个很好的 api 来发送电子邮件,并且有一个节点模块(https://npmjs.org/package/postmark

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-19
      • 2019-03-28
      • 2017-09-16
      • 2022-07-27
      相关资源
      最近更新 更多