Oauth 2.0 nodeEmailer OAUTH Gmail连接(错误:connect-ETIMEDOUT 74.125.140.108:465)
我正在尝试使用OAuth2.0使用nodeEmailer发送带有Gmail API的电子邮件 我启用了Gmail API,我有clientId、clientSecret、refreshToken和accessToken(refreshToken和accessToken是从developers.google.com/OAuthPlayed获得的),因为这些都是OAUTH工作所必需的 我遵循了每一个细节表() 但我有以下错误Oauth 2.0 nodeEmailer OAUTH Gmail连接(错误:connect-ETIMEDOUT 74.125.140.108:465),oauth-2.0,smtp,gmail-api,nodemailer,smtp-auth,Oauth 2.0,Smtp,Gmail Api,Nodemailer,Smtp Auth,我正在尝试使用OAuth2.0使用nodeEmailer发送带有Gmail API的电子邮件 我启用了Gmail API,我有clientId、clientSecret、refreshToken和accessToken(refreshToken和accessToken是从developers.google.com/OAuthPlayed获得的),因为这些都是OAUTH工作所必需的 我遵循了每一个细节表() 但我有以下错误 { Error: connect ETIMEDOUT 74.125.140
{ Error: connect ETIMEDOUT 74.125.140.108:465
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
errno: 'ETIMEDOUT',
code: 'ESOCKET',
syscall: 'connect',
address: '74.125.140.108',
port: 465,
command: 'CONN' }
但是,当我使用普通用户名和密码时,会遇到一个问题:没有连接超时错误,因为我已经启用了不太安全的应用程序访问表单(),所以使用普通用户名和密码发送电子邮件时没有错误但是这不是一个好方法,所以OAUTH是解决方案
以下是我的代码,供您检查(这是一个express应用程序)是否正在运行
var nodemailer=require('nodemailer');
var transporter=nodeEmailer.createTransport({
主机:“smtp.gmail.com”,
港口:465,
安全:是的,
服务:“gmail”,
认证:{
类型:“OAuth2”,
用户:'mygmailaddress@gmail.com',
clientId:'clientId',
clientSecret:“clientSecret”,
refreshToken:'从获取的刷新令牌https://developers.google.com/oauthplayground',
accessToken:'访问令牌也从https://developers.google.com/oauthplayground'
}
});
var mailpoptions={
从‘我’,
至:'',
主题:'主题',
文字:“一些东西”,
};
transporter.sendMail(邮件选项,(错误,响应)=>{
如果(错误){
console.log(error);//总是给出错误:connect-ETIMEDOUT 74.125.140.108:465
}否则{
控制台日志(响应);
}
});
它甚至不尝试登录,因为当登录失败时,它会给出错误的凭证错误(使用普通用户名和密码检查)
*请注意,请不要将此问题标记为重复问题,因为我已检查了几乎所有其他问题和答案,但没有任何结果
有些人说这是因为防火墙设置,我也检查过了,但没有工作
那么问题是什么以及如何解决呢?在查看了您的问题之后,我假设在生成OAuth凭据(例如(clienId和Clientsecret))时,您没有在连接屏幕上添加您的作用域,因为您需要谷歌的验证表来添加这些凭据的作用域 您必须已在()上将其添加到您的作用域中,但我确信在生成凭据之前,您也已在“同意”屏幕上将其添加到您的作用域中 由于您处于开发模式,并且在本地主机上运行应用程序,所以您没有私有域和隐私策略
在生成clientId和ClientCret之前添加到您的作用域将解决您的问题在查看您的问题后,我假设在生成OAuth凭据时,例如(clienId和Clientsecret)您没有在“连接”屏幕上添加您的作用域,因为您需要从google验证表中添加这些凭据的作用域 您必须已在()上将其添加到您的作用域中,但我确信在生成凭据之前,您也已在“同意”屏幕上将其添加到您的作用域中 由于您处于开发模式,并且在本地主机上运行应用程序,所以您没有私有域和隐私策略
在生成clientId和ClientCret之前添加到您的范围将解决您的问题您的端口号对于gmail是错误的。gmail使用这种格式
const nodeMailer = require('nodemailer');
let transporter = nodeMailer.createTransport({
host: "smtp.gmail.com",
port: 587,
secure: false, // true for 587, false for other ports
requireTLS: true,
auth: {
user: your email,
pass: your password,
},
});
let mailOptions = {
from: 'from@gmail.com',
to: 'to@gmail.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
你的端口号对于gmail是错误的。gmail使用这种格式
const nodeMailer = require('nodemailer');
let transporter = nodeMailer.createTransport({
host: "smtp.gmail.com",
port: 587,
secure: false, // true for 587, false for other ports
requireTLS: true,
auth: {
user: your email,
pass: your password,
},
});
let mailOptions = {
from: 'from@gmail.com',
to: 'to@gmail.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});