I’m vary new to express and I think I’m struggling with something what is not that hard…
I have a function sendEmail
exports.sendEmail = async (req, res) => {
const transport = nodemailer.createTransport({
host: process.env.MAIL_HOST,
port: process.env.MAIL_PORT,
secure: false,
auth: {
user: process.env.MAIL_USER,
pass: process.env.MAIL_PASSWORD,
},
tls: {
rejectUnauthorized: false,
},
});
await transport.sendMail(
{ body },
(err, info) => {
console.log(err);
console.log(info);
// here is a problem
if (err) {
res.status(200).json({ msg: 'error' });
throw err;
} else {
res.status(200).json({ msg: 'mesage
has been sent' });
}
);
This function works fine – email is send. But what I want to achieve is send info to browser with info ‘is sent’ or ‘error’.
In frontend I have this code:
await axios.all([
axios.post(`${process.env.REACT_APP_DOMAIN}/api/send-email`, {
data,
}),
axios
.get(`${process.env.REACT_APP_DOMAIN}/api/send-email`)
.then((res) => {
console.log(res);
}),
]);
axios.post works fine, but axios.get is not. The response I get doesn’t contain data I want.
Could anyone explain me how to send data I need to after email is sent?
Thanks.