问题描述
在Openshift的node.js单齿轮不可扩展应用程序中使用nodemailer模块时,我遇到了一些问题.正如文档所建议的那样,我初始化了传输器对象并使用了sendMail函数.我的代码的简化版本是
I'm facing some problems using the nodemailer module in my node.js single gear non-scalable application in Openshift. As the documentation suggested, I initialized the transporter object and used the sendMail function. A simplified version of my code is
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: '[email protected]',
pass: 'mypassword'
}
});
var mail = {
from: '[email protected]',
to: '[email protected]',
subject: 'Test mail',
html: 'Test mail'
};
transporter.sendMail(mail, function(error, info) {
if(error){
console.log(error);
}else{
console.log(info);
}
});
当我在本地计算机上运行该代码时,该代码正确运行,但是当我尝试在服务器上执行该代码时,出现了ETIMEDOUT
错误,好像应用程序无法连接到smtp服务器.
This code works correctly when I run it on my local machine, but when I try to execute it on the server I got an ETIMEDOUT
error, as if the application couln't connect to the smtp server.
{ [Error: connect ETIMEDOUT] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect' }
我尝试增加超时连接参数,但是得到的结果相同.
I've tried to increase the timeout connection parameter, but I got the same results.
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: '[email protected]',
pass: 'mypassword'
},
connectionTimeout: 5 * 60 * 1000, // 5 min
});
我缺少任何防火墙或默认的Openshift设置或环境变量吗?
Is there any firewall or default Openshift settings or enviroment variable I'm missing?
推荐答案
我还需要运行一些测试,但是我想我已经找出了问题所在.通过用户名和密码进行身份验证是Gmail的不安全身份验证方法.如Nodemailer文档中所述
I've to run a few more tests, but I think I figured out what the problem was. The authentication via username and password is a not-secure authentication method for Gmail. As written in the Nodemailer documentation
我使用XOAuth2升级了我的授权方法,这在指南,现在邮件已正确发送.
I upgraded my authorization method using XOAuth2, as well explained in this guide and now the mails are correctly sent.
这篇关于使用Nodejs Openshift应用程序中的nodemailer的ETIMEDOUT连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!