react add data from MongoDB to email

pretty new to react only been doing it for a couple of weeks and I’m working on a project for personal use to send an email to my email using nodemailer which I have managed to do. the next part I want to do is add data to the email that will come from my MongoDB database like the order number, customer name and status of the job I’ve searched high and low on youtube and google and not really finding anything on the issue

also, it only runs when I type node server.js and then it automatically sends the email which I don’t want I want it to run when submit is clicked when a status is updated in the database.

Here is the code for what I have on server.js

require('dotenv').config();

const nodemailer = require('nodemailer');


let transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: process.env.EMAIL,
    pass: process.env.PASSWORD
    }
});


let mailOptions = {
    from: 'group2021@gmail.com',
    to: 'edge@gmail.com',
    subject: 'Project Update',
    text: 'Hello {{name}} please find this email as an update to you project.'
};

transporter.sendMail(mailOptions, function(err, data) {
    if(err) {
        console.log('Error Occured!', err);
    } else {
        console.log('Email Sent!')
    }
});

6 thoughts on “react add data from MongoDB to email”

Leave a Comment