Я не совсем понимаю, как пройти объект в html nodemailer?
И я не хочу использовать пакет email-templates.
Мой код:
const nodemailer = require('nodemailer');
const transpoter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'user@gmail.ca',
pass: 'xxxxxxx'
}
});
const ctc = {
'1': {
'query': {
'lastUpdated': 'yesterday',
'Type': 'Personal'
},
'count': 16
},
'2': {
'query': {
'lastUpdated': 'today',
'Type': 'Business'
},
'count': 12
},
};
const mailOptions = {
from: 'liu1cm@uwindsor.ca',
to: '415110593@qq.com',
subject: 'Hello',
html: `
<h1>Hello, Datahub fellows</h1>
<table>
<th>
<tr>Query</tr>
<tr>Count</tr>
</th>
{% for el in ctc %}
<P>${JSON.stringify(ctc[el].query)}</P>
<p>${ctc[el].count}</p>
{% endfor %}
</table>
`
};
transpoter.sendMail(mailOptions, (err, info) => {
if (err) {
console.log(err);
} else {
console.log('Email sent');
}
});
Я попробовал свой код, но всегда получал ошибку ReferenceError: el is not defined
.
Я хочу обойти объект ctc
и поместить каждый элемент в ctc
в таблицу.У кого-нибудь есть идеи?