【发布时间】:2019-01-12 15:52:33
【问题描述】:
我使用 NodeMailer 和 Gmail API 从我的服务器发送电子邮件。当我在本地主机上测试它时,一切都很好。但是当我在我的服务器上运行它时,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;
}
}
【问题讨论】:
标签: javascript node.js gmail nodemailer