Nodemailer / Mailgun Sender选项

时间:2016-05-26 16:10:05

标签: javascript node.js email mailgun nodemailer

我在Node.js应用程序中使用Nodemailer(https://github.com/nodemailer/nodemailer)和mailgun。

我想要做的是在邮件中指定“发件人”。我发送的电子邮件如下:

mysqli_connect

在Gmail中,它显示为: 来自:名字姓氏< test@example.com>

对于我的客户端,它显示为: 来自:job=live.no@mg.lillesand.com [mailto:job=live.no@mg.lillesand.com]

我怀疑它与电子邮件标题中的“发件人”参数有关。

来自Nodemailer文档,它说

  

sender - 发件人:字段中显示的电子邮件地址   (总是喜欢,如果你不确定使用哪一个)

我尝试设置发件人选项无效。

var auth = {
    auth: {
        api_key: process.env.MAILGUN_API_KEY,
        domain: process.env.MAILGUN_DOMAIN
    }
}

var transport = nodemailer.createTransport(mailgunTransport(auth));

var recipients = process.env.MAILGUN_RECIPIENTS;

    var mail = {
        from: contactPerson.firstName + " " + contactPerson.lastName + " " + "<" + contactPerson.email + ">",
        to: recipients,
        subject: "Innspill til bredbåndsutbygging",
        text: message
    }

    transport.sendMail(mail, function (error, info) {
        if (error) {
            console.log("Error occurred!");
            console.log(error);
        } else {
            console.log("Email sendt!");
            console.log(info);
        }
    });

1 个答案:

答案 0 :(得分:0)

I actually wanted to add a comment, but don't have enough reputation. I wanted to give you some tips where to look for, because I am not sure what kind of questions you have there.

Did you check the client side JS-file for any misplaced quotes, that could be interpreted for one service but not for the other?

Also check what kind of encoding you are using. On client if you have a form you can set XMLHttpRequest().setRequestHeader("Content-type", "application/x-www-form-urlencoded") You can encode on the server side as well, using certain node modules like express. Note, that you can display html and plain text. html will ignore escape signs like \n

I am almost certain that your problems lies in the configuration of Mailgun. In my very hard learning I have not encountered your display problem.

I hope it helps.