0
Searching for user tickets and customizing a message for each one can be a value requirement for a customer
I’m trying to do just that
A loop to customize a message to a found user
I have the following code
const lista = [
{nome: 'Carlos', email: '[email protected]', idUsuario: 1},
{nome: 'Bruno', email: '[email protected]', idUsuario: 2},
{nome: 'Gonçalves', email: '[email protected]', idUsuario: 3},
{nome: 'Brito', email: '[email protected]', idUsuario: 4},
]
const objetoParaEnvio = {}
lista.map(async (l,i) => {
const dadosUsuario = l.dataValues
const { email, nome, idUsuario } = dadosUsuario
objetoParaEnvio.para = email
objetoParaEnvio.msg = 'Teste de envio'
await enviarEmail( objetoParaEnvio )
return l
})
const enviarEmail = body => {
return new Promise(async (resolve, reject)=>{
const mailOption = await mailOptionConfig()
mailOption.subject = body.assunto
mailOption.to = body.para
const templateFile = path.resolve('src','email','template-email.html')
const templateData = fs.readFileSync(templateFile,{encoding:'utf-8'});
const template = handlebars.compile(templateData.toString());
const html = template(
{ content: body.msg}
);
mailOption.html = html
let transport = await transporter()
transport.sendMail( mailOption, async (error, info) =>{
if(error) {
console.log('Problema no envio', error.message);
resolve({status: false})
}else{
console.log('E-mail enviado!');
resolve({status: true})
}
})
})
}
The html template I have it here
<h1 style='color:#fff;background:#0E1D46;padding: 10px;margin:0; vertical-align:bottom;border-left: 10px solid #2b57ce;border-right: 10px solid #2b57ce;font-family:Roboto;'>
</h1>
<blockquote style='font-size:14pt;margin:0;padding: 40px 30px;border-left: 10px solid #0E1D46;border-right: 10px solid #0E1D46;font-family:Roboto;'>
<p>{{{ content }}}</p>
<br>
<span style="font-size: 9px">Esse e-mail é gerado automaticamente, não precisa respondê-lo</span>
</blockquote>
But when executing the code:
It only picks up sends to the last item of the array 4 times, even reading all the items
Where can I be missing?