I'm building an email-sender app using nodemailer and MySQL DB and send multiple emails.
code:
let emails= `select email from users`
db.query(emails,(err, email, fields)=>{
// console.log(email);
})
const options = {
from: 'h.codetests@outlook.com',
to: emails,
subject: 'nodemailer test',
text: 'noooooodemailer test'
}
// ? we will passe options and function of (err, info) in sendmail method
transporter.sendMail(options, (err, info)=>{
if (err) {
console.log(err);
return
}
console.log(`sent: ${info.response}`);
})
and I got this error
Database is connected successfully !
Error: No recipients defined
at SMTPConnection._formatError (E:\vs work\email sender app\node_modules\nodemailer\lib\smtp-connection\index.js:784:19)
at SMTPConnection._setEnvelope (E:\vs work\email sender app\node_modules\nodemailer\lib\smtp-connection\index.js:1001:34) at SMTPConnection.send (E:\vs work\email sender app\node_modules\nodemailer\lib\smtp-connection\index.js:615:14)
at sendMessage (E:\vs work\email sender app\node_modules\nodemailer\lib\smtp-transport\index.js:227:28)
at E:\vs work\email sender app\node_modules\nodemailer\lib\smtp-transport\index.js:285:25
at SMTPConnection._actionAUTHComplete (E:\vs work\email sender app\node_modules\nodemailer\lib\smtp-connection\index.js:1550:9)
at SMTPConnection.<anonymous> (E:\vs work\email sender app\node_modules\nodemailer\lib\smtp-connection\index.js:1490:18)
at SMTPConnection._processResponse (E:\vs work\email sender app\node_modules\nodemailer\lib\smtp-connection\index.js:947:20)
at SMTPConnection._onData (E:\vs work\email sender app\node_modules\nodemailer\lib\smtp-connection\index.js:749:14)
at TLSSocket.SMTPConnection._onSocketData (E:\vs work\email sender app\node_modules\nodemailer\lib\smtp-connection\index.js:189:44) {
code: 'EENVELOPE',
command: 'API'
Is there an alternative way to send multiple emails at once? or is there a way for me to make sure my app send multiple emails from the database(MySQL)?