我嘗試使用Nodemailer與我的GMail帳戶一起發送電子郵件,但它不起作用,它可以在本地但在我的遠程服務器上運行我收到來自Google的電子郵件「某人正在使用您的帳戶....「帶有訪問令牌的Nodemailer和GMail
我該怎麼辦?
exports.contact = function(req, res){
var name = req.body.name;
var from = req.body.from;
var message = req.body.message;
var to = '******@gmail.com';
var transport = nodemailer.createTransport("SMTP", {
service: 'Gmail',
auth: {
XOAuth2: {
user: "******@gmail.com",
clientId: "*****",
clientSecret: "******",
refreshToken: "******",
}
}
});
var options = {
from: from,
to: to,
subject: name,
text: message
}
transport.sendMail(options, function(error, response) {
if (error) {
console.log(error);
} else {
console.log(response);
}
transport.close();
});
}
回答這裏 - http://stackoverflow.com/q/24098461/4640499。 –