【问题标题】:get data from api in nodemailer node.js config从 nodemailer node.js 配置中的 api 获取数据
【发布时间】:2021-09-05 20:45:28
【问题描述】:

我正在尝试创建一个发件人配置 nodemailer node.js,它是从 API 获取的动态数据, 示例:

let transporter = nodemailer.createTransport({
host: fromAPI,
port: fromAPI,
secure: fromAPI,
auth: {
    user: fromAPI,
    pass: fromAPI
}});

“fromAPI”是来自api的动态数据

我尝试从 axios 构建,但它不起作用,有什么建议吗?

axios.get('http://localhost:4500/api/email_config', {
        headers: {
            'Content-Type': 'application/json',
            Authorization: `Bearer mytoken`,
        },
    }) 
 .then(function (response) {
    console.log(response.data); 
})
.catch(function (error) {
    console.log(error);
});

【问题讨论】:

  • 主机的“fromAPI”是指response.data.host等吗?
  • 是的,比如 response.data.host

标签: node.js api express nodemailer


【解决方案1】:
let transporter = nodemailer.createTransport({
host: data.host,
port: fromAPI,
secure: fromAPI,
auth: {
    user: data.user,
    pass: data.pass
}});

你试过这样吗?

【讨论】:

    猜你喜欢
    • 2018-03-11
    • 2015-12-16
    • 1970-01-01
    • 2018-10-07
    • 2016-06-21
    • 2021-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多