我尝试配置gmail以通过oauth2.0发送电子邮件。 我使用passport.js允许用户通过谷歌oauth2.0
登录我们的应用程序示例:
这些是我使用的Google范围:
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
我确实无法找到问题所在。任何人都可以帮忙吗?