我尝试使用 Nodemailer 通过我的 GMail 帐户发送电子邮件,但它不起作用,它在本地工作,但在我的远程服务器上,我收到来自 Google 的电子邮件“有人正在使用您的帐户......”
我能怎么做 ?
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();
});
}