简体   繁体   中英

get data from api in nodemailer node.js config

I'm trying to create a sender config nodemailer node.js, that is fetched dynamic data coming from API, example:

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

"fromAPI" it's dynamic data coming from api

I tried to build from axios but it doesn't work, any suggestions?

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);
});
let transporter = nodemailer.createTransport({
host: data.host,
port: fromAPI,
secure: fromAPI,
auth: {
    user: data.user,
    pass: data.pass
}});

have you tried like this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM