发送邮件与nodemailer - 邮件从字段不正确 [英] sending mail with nodemailer - email from field incorrect

查看:127
本文介绍了发送邮件与nodemailer - 邮件从字段不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用nodemailer设置联系表单。以下是我的app.js中的内容:

Trying to set up a contact form with nodemailer. Here's what's in my 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模板如下所示:

And my contact.jade template looks like this:

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,而不是我输入到模板的电子邮件字段。任何想法

The email now works, but comes from myemailaddress rather than the one I enter into the email field on the template. Any ideas

推荐答案

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

Gmail and many other email services don't allow you to send messages with various FROM field.

这篇关于发送邮件与nodemailer - 邮件从字段不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆