[英]NodeMailer Response Nothing on Server
I use NodeMailer and Gmail API to send email from my server. 我使用NodeMailer和Gmail API从服务器发送电子邮件。 When I test it on localhost, everything's fine.
当我在本地主机上对其进行测试时,一切都很好。 But when i run it on my server, Nodemailer responses nothing, nothing is sent and I don't know why.
但是,当我在服务器上运行它时,Nodemailer没有响应,没有任何响应,我也不知道为什么。 Thanks for reading my question.
感谢您阅读我的问题。 Please answer, thank you.
请回答,谢谢。 :'( Here is my code:
:'(这是我的代码:
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;
}
}
idk if you still need help with this but i'm answering : idk如果您仍然需要帮助,但是我在回答:
const mailConfig = await GmailConfig.createConfig();
const transporter = emailer.createTransport(mailConfig);
transporter.use('compile', markdown())
await transporter.sendMail(option, function (error, info)); // callback here
console.log(info); // log the body and status etc...
transporter.close();
return 'success';
So, basically if you want a response on the server side send a callback returning the response from the sender. 因此,基本上,如果您希望服务器端的响应发送一个回调,以从发送方返回响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.