我尝试将 gmail 配置为通过 oauth2.0 发送电子邮件。我正在使用 passport.js 允许用户通过 google oauth2.0 登录我们的应用程序
例子:
这些是我使用的谷歌范围:
app.get('/auth/google',
passport.authenticate('google',{ scope: ['https://www.googleapis.com/auth/plus.login','https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile','https://mail.google.com/'],accessType: 'offline', approvalPrompt: 'force' }),
function(req, res){
});
这些是使用 passport.js 和 nodemailer 传输配置的 Google 身份验证
passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "http://localhost:3000/auth/google/callback"
},
function(accessToken, refreshToken, profile, done) {
transport = nodemailer.createTransport("SMTP", {
service: 'Gmail',
auth: {
XOAuth2: {
user: profile._json.email,//"example.user@gmail.com",
clientId: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
refreshToken: refreshToken,
accessToken: accessToken,
timeout: 3600
}
},
debug: true
});
process.nextTick(function () {
return done(null, {
access_token: accessToken,
refresh_token: refreshToken,
profile: profile
});
});
}
));
发送邮件时出现错误,错误是:
已配置 SMTP
发送邮件
Error occured
{ [Error: connect ETIMEDOUT]
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
stage: 'init' }
connect ETIMEDOUT
Closing connection to the server
我没能找到问题。有人可以帮忙吗?