0

I am trying to send emails through nodemailer, and I've used it multiple times with my gmail account... the problem is, I don't want to use my gmail account now, and I want to use my business email so I could send out emails to clients on a regular...

I have it set up like this right now, but not sure how to do it without gmail / smtp:

app.post('/sendBatchEmail', (req, res) => {
var emails = [];
var emailSubject = req.body.emailSubject;
var emailMessage = req.body.emailMessage;
//perform db2 send

var sendEmail = "select * from testEmails"
ibmdb.open(ibmdbconnMaster, function (err, conn) {
  if (err) return console.log(err);
  conn.query(sendEmail, function (err, rows) {
    if (err) {
      console.log(err);
    }
    for (var i = 0; i < rows.length; i++) {
      emails.push(rows[i].EMAIL)
    }
   
    //send email
    async function main() {
      // Generate test SMTP service account from ethereal.email
      // Only needed if you don't have a real mail account for testing
      let testAccount = await nodemailer.createTestAccount();
  
      // create reusable transporter object using the default SMTP transport
      let transporter = nodemailer.createTransport({
        host: "smtp.gmail.com",
        port: 587,
        secure: false, // true for 465, false for other ports
        auth: {
          user: "x",
          pass: "x",
        },
      });
  
      // send mail with defined transport object
      let sendBatch = await transporter.sendMail({
        from: "", // sender address
        to: "xxxxx@gmail.com",
        bcc: emails, // list of receivers
        subject: emailSubject, // Subject line
        text: emailMessage, // plain text body
      });
  
      console.log("Message sent: %s", sendBatch.messageId);
     }
  
    main().catch(console.error);
    res.redirect("/index");

    conn.close(function () {
      console.log("closed the function app.get(/account)");
    });
  });
});

I am not sure how to not use smtp server so I can use biz email, or even if this is possible! Thanks in advance for help :)

 })
Gianluca
  • 900
  • 8
  • 27

1 Answers1

-1

As you can do this using nodemailer, but sending an email without a SMTP is not recommended as there are much higher chances of being rejected or put into spam folder. I'm pretty sure gmail like services will put the emails in Spam folder. here is how you can implement it:

let transporter = nodemailer.createTransport({
        host: "smtp.example.com",
        port: 587,
        secure: false, // true for 465, false for other ports
        auth: {
          user: "x",
          pass: "x",
        },
      });
  
      // send mail with defined transport object
      let sendBatch = await transporter.sendMail({
        from: "<foo@example.com>", // sender address
        to: "xxxxx@gmail.com",
        bcc: emails, // list of receivers
        subject: emailSubject, // Subject line
        text: emailMessage, // plain text body
      });
  
      console.log("Message sent: %s", sendBatch.messageId);
     }

For more details you can check here1 and here2

Apoorva Chikara
  • 8,277
  • 3
  • 20
  • 35