A
A
AlexCruel2019-09-07 18:37:53
Node.js
AlexCruel, 2019-09-07 18:37:53

What can I do to send an email to specific users?

I need to send an email to those whose mail status is unconfirmed (NULL) from a MySQL database. I use "nodemailer" Tried like this

// script.js
module.exports = {
    mail: pool.query('SELECT email FROM clients WHERE email_status IS NULL')
}

// nodemailer.js
var mail = require('./script');
let mailOptions = {
    from: '[email protected]',
    to: mail.mail,
    subjects: 'Testing',
    text: 'It works!'
}

But it doesn't work, of course.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexCruel, 2019-09-07
@AlexCruel

I decided (when entering mail on the form, a letter is immediately sent to the specified address :) ):

const mailer = message => {
//nodemailer.js
    transporter.sendMail(message, function(err, data) {
        if (err) {
            console.log('Error!!!', err);
        } else {
            console.log('Cool!!!');
        }
    })
}

module.exports = mailer;

//script.js
const mailer = require("./nodemailer");
const message = {
        from: 'Hello! <[email protected]>',
        to: req.body.email,
        
    }
mailer(message);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question