Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

304
Views
Nodemailer not sending email, displays "Message sent:Undefined"

It was working and then it wasn't. I sent a few mails and after a while it stopped working. I get "Message sent:Undefined" (node:9048) UnhandledPromiseRejectionWarning: Error: spawn sendmail ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)

I have no idea why.

Frontend- Axios console logs the response data therefore the server and the frontend both are working. It is just the issue with the Nodemailer.

Any help is appreciated. Thanks!

const express = require("express");
const app = express();
const cors = require("cors");
const nodemailer = require("nodemailer");
const path = require("path");
const fs = require("fs");
const readData = path.join(__dirname, "../email_take2/data.json");
const { v4: uuidv4 } = require("uuid");


app.use(express.json());
app.use(cors());

const port = process.env.PORT || 5000;
app.listen(5000, () => console.log(`Listening at port ${port}`));
if (process.env.NODE_ENV === "production") {
  // Set static folder
  app.use(express.static("../client/build"));

  app.get("*", (req, res) => {
    res.sendFile(path.join(__dirname, "../client", "build", "index.html"));
  });
}
function listUserData() {
  const data = fs.readFileSync(readData);
  return JSON.parse(data);
}

app.post("/sendEmail", function (req, res) {
  console.log(req.body);
  const emailInfo = {
    id: uuidv4(),
    email: req.body.email,
    cc: req.body.cc,
    message:req.body.message,
  };
  const dataArray = listUserData();
  dataArray.push(emailInfo);
  fs.writeFileSync(readData, JSON.stringify(dataArray));
  res.send(emailInfo);
  console.log("SentBody", emailInfo);

  let transporter = nodemailer.createTransport({
    sendmail:true,
    host: "smtp.outlook.com",
    port: 587,
    secure: false, // true for 465, false for other ports
    tls: {
        ciphers: "SSLv3",
           },
    auth: {
      user: "memail@outlook.com", // generated ethereal user
     pass: "mypw", // generated ethereal passwordAccount.pass, 
    },
  });


  // send mail with defined transport object
  let info = transporter.sendMail({
    from: '"Fred Foo ๐Ÿ‘ป" <foo@example.com>', // sender address
    to: "garbageacc7878@outlook.com", // list of receivers
    subject: "Hello โœ”", // Subject line
    text: "Hello world?", // plain text body
    html: "<b>Hello world?</b>", // html body
  });
  console.log("Message sent: %s", info.messageId);
  return emailInfo;
});
about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

transporter.sendMail returns a promise, that's why your console log has undefined. So either attach a .then and .catch.

transporter.sendMail(...)
.then((data)=>{console.log('Mail sent', data)})
.catch(err => {console.error('Failure',err)})

Or make your request handler an async function and use async await and use tryCatch.

try{
let data = await transporter.sendMail(...)
console.log('Mail sent', data)
} catch (err) {
console.error('Failure',err)
}

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!