使用 nodemailer 发送电子邮件不在远程工作但在本地主机工作
Sending an email using nodemailer not working on remote but working in local host
您好,我正在使用 nodemailer 发送电子邮件。它在本地主机上工作正常,但是当我将它部署到远程网站时它不起作用。
当我尝试在远程网站上发送电子邮件时收到以下错误消息:
ERROR === { Error: Invalid sender “<Myemailaddress@gmail.com>”
2016-08-15T05:05:01.034175+00:00 app[web.1]: at SMTPConnection._formatError (/app/node_modules/smtp-connection/lib/smtp-connection.js:493:15)
2016-08-15T05:05:01.034175+00:00 app[web.1]: at SMTPConnection._setEnvelope (/app/node_modules/smtp-connection/lib/smtp-connection.js:688:30)
2016-08-15T05:05:01.034176+00:00 app[web.1]: at SMTPConnection.send (/app/node_modules/smtp-connection/lib/smtp-connection.js:364:10)
2016-08-15T05:05:01.034177+00:00 app[web.1]: at SMTPTransport.<anonymous> (/app/node_modules/nodemailer-smtp-transport/lib/smtp-transport.js:126:24)
2016-08-15T05:05:01.034178+00:00 app[web.1]: at /app/node_modules/nodemailer-smtp-transport/lib/smtp-transport.js:162:21
2016-08-15T05:05:01.034178+00:00 app[web.1]: at SMTPConnection._actionAUTHComplete (/app/node_modules/smtp-connection/lib/smtp-connection.js:1185:5)
2016-08-15T05:05:01.034179+00:00 app[web.1]: at SMTPConnection.<anonymous> (/app/node_modules/smtp-connection/lib/smtp-connection.js:307:22)
2016-08-15T05:05:01.034180+00:00 app[web.1]: at SMTPConnection._processResponse (/app/node_modules/smtp-connection/lib/smtp-connection.js:634:16)
2016-08-15T05:05:01.034180+00:00 app[web.1]: at SMTPConnection._onData (/app/node_modules/smtp-connection/lib/smtp-connection.js:458:10)
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'Mailgun',
auth: {
user: process.env.MAILGUN_USERNAME,
pass: process.env.MAILGUN_PASSWORD
}
});
/**
*
*/
exports.contact = function(from, to) {
var mailOptions = {
from: from.name + ' ' + '<'+ from.email + '>',
to: to.email,
subject: from.subject || "No Subject",
text: from.message
};
transporter.sendMail(mailOptions, function(err) {
if (err){
console.log("ERROR === ", err);
}
});
};
我已经为安全性较低的应用程序授予了对我的电子邮件地址的访问权限,所以这应该不是问题所在。有谁知道为什么它可以在本地网站上运行,而不能在远程网站上运行?
好吧,添加括号似乎可以防止 nodemailer 在远程工作,即使它在本地工作。
我将代码更改为以下内容:
var mailOptions = {
from: from.email
to: to.email,
subject: from.subject || "No Subject",
text: from.message
};
现在可以在我的远程服务器上发送电子邮件了
Nodemailer does not support proxies and currently there is no plan to add any support for these, sorry.
从 here
暂时禁用验证码
您好,我正在使用 nodemailer 发送电子邮件。它在本地主机上工作正常,但是当我将它部署到远程网站时它不起作用。
当我尝试在远程网站上发送电子邮件时收到以下错误消息:
ERROR === { Error: Invalid sender “<Myemailaddress@gmail.com>”
2016-08-15T05:05:01.034175+00:00 app[web.1]: at SMTPConnection._formatError (/app/node_modules/smtp-connection/lib/smtp-connection.js:493:15)
2016-08-15T05:05:01.034175+00:00 app[web.1]: at SMTPConnection._setEnvelope (/app/node_modules/smtp-connection/lib/smtp-connection.js:688:30)
2016-08-15T05:05:01.034176+00:00 app[web.1]: at SMTPConnection.send (/app/node_modules/smtp-connection/lib/smtp-connection.js:364:10)
2016-08-15T05:05:01.034177+00:00 app[web.1]: at SMTPTransport.<anonymous> (/app/node_modules/nodemailer-smtp-transport/lib/smtp-transport.js:126:24)
2016-08-15T05:05:01.034178+00:00 app[web.1]: at /app/node_modules/nodemailer-smtp-transport/lib/smtp-transport.js:162:21
2016-08-15T05:05:01.034178+00:00 app[web.1]: at SMTPConnection._actionAUTHComplete (/app/node_modules/smtp-connection/lib/smtp-connection.js:1185:5)
2016-08-15T05:05:01.034179+00:00 app[web.1]: at SMTPConnection.<anonymous> (/app/node_modules/smtp-connection/lib/smtp-connection.js:307:22)
2016-08-15T05:05:01.034180+00:00 app[web.1]: at SMTPConnection._processResponse (/app/node_modules/smtp-connection/lib/smtp-connection.js:634:16)
2016-08-15T05:05:01.034180+00:00 app[web.1]: at SMTPConnection._onData (/app/node_modules/smtp-connection/lib/smtp-connection.js:458:10)
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'Mailgun',
auth: {
user: process.env.MAILGUN_USERNAME,
pass: process.env.MAILGUN_PASSWORD
}
});
/**
*
*/
exports.contact = function(from, to) {
var mailOptions = {
from: from.name + ' ' + '<'+ from.email + '>',
to: to.email,
subject: from.subject || "No Subject",
text: from.message
};
transporter.sendMail(mailOptions, function(err) {
if (err){
console.log("ERROR === ", err);
}
});
};
我已经为安全性较低的应用程序授予了对我的电子邮件地址的访问权限,所以这应该不是问题所在。有谁知道为什么它可以在本地网站上运行,而不能在远程网站上运行?
好吧,添加括号似乎可以防止 nodemailer 在远程工作,即使它在本地工作。
我将代码更改为以下内容:
var mailOptions = {
from: from.email
to: to.email,
subject: from.subject || "No Subject",
text: from.message
};
现在可以在我的远程服务器上发送电子邮件了
Nodemailer does not support proxies and currently there is no plan to add any support for these, sorry.
从 here
暂时禁用验证码