Я использую NodeMailer и Gmail API для отправки электронной почты с моего сервера. Когда я тестирую его на localhost, все нормально. Но когда я запускаю его на своем сервере, Nodemailer ничего не отвечает, ничего не отправляется, и я не знаю почему.
Спасибо за чтение моего вопроса. Пожалуйста, ответьте, спасибо. : '(
Вот мой код:
const { google } = require('googleapis');
const OAuth2 = google.auth.OAuth2;
const oauth2Client = new OAuth2(
AuthConfig.clientId,
AuthConfig.clientSecret,
'https://developers.google.com/oauthplayground'
);
oauth2Client.setCredentials({
refresh_token: AuthConfig.refreshToken
});
export default class GmailConfig {
static async createConfig () {
const tokens = await oauth2Client.getRequestHeaders();
const accessToken = tokens.Authorization;
return {
service: 'gmail',
auth: {
type: 'OAuth2',
user: 'address@gmail.com',
clientId: AuthConfig.clientId,
clientSecret: AuthConfig.clientSecret,
refreshToken: AuthConfig.refreshToken,
accessToken
}
}
}
}
async sendMail (receiver, subject, content) {
try {
const option = {
from: 'address',
to: receiver,
subject: subject,
markdown: content
}
const mailConfig = await GmailConfig.createConfig();
const transporter = emailer.createTransport(mailConfig);
transporter.use('compile', markdown())
await transporter.sendMail(option);
transporter.close();
return 'success';
}
catch (error) {
console.log(error);
return error;
}
}