我的数据库中有Mailgun设置配置。所有我想要的Mailgun客户端密钥,用户名,和电子邮件应该从数据库中提取任何邮件去客户端。但我不能设置数据。from: mailgun_email,
这部分也是我们从数据库中获取的。请帮助我如何设置数据。还有一件事,如果我在电子邮件文件之外调用配置文件,它会给我一个错误mongoose错误,这是我所理解的,即在数据库设置缓冲超时错误之前调用配置文件。
错误MongooseError: Operation configurations.findOne() buffering timed out after 10000ms
邮件文件
let mg;
const configuration = async () => {
const res = await Configuration.findById({ _id: process.env.CONFIGURATION_ID });
let key = res.mailgun_api_key;
let username = res.mailgun_username;
return mailgun.client({
username,
key,
});
};
const successOnRegisterMail = (user_email, user_name) => {
configuration();
try {
mg.messages
.create("sandbox1f0bc2b687fc416cbd9bdf7a7d1bc24c.mailgun.org", {
from: mailgun_email,
to: [user_email],
subject: "",
text: "Congratulation you've been successfully registered.",
html: `<p>Hello ${user_name}</p> <br /><br /> <p>Congratulation you've been successfully registered.</p><br /> Best Regards, <br /> Team Developers`,
})
.then((msg) => console.log(msg)) // log response data
.catch((error) => console.log(error)); // log any error
} catch (err) {
console.log("Error from Mail: ", err);
}
};
1条答案
按热度按时间uqdfh47h1#
经过多次尝试,我终于找到了答案。
在邮件里用这个