The error message is incredibly long, but here is a brief excerpt:
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Object
at PassThrough.Writable.write (_stream_writable.js:289:13)
at PassThrough.Writable.end (_stream_writable.js:583:10)
at Immediate._onImmediate (C:\Users\small\desktop\career-change\coding-round-2\portfolio-round1\recipe-app\projectv2\node_modules\nodemailer\lib
\mime-node\index.js:969:46)
at processImmediate (internal/timers.js:456:21) {
code: 'ERR_INVALID_ARG_TYPE'
}
This is my first experience with nodemailer or any email service. Initially, I used it with my personal gmail account, but encountered issues when gmail blocked it due to security concerns. To address this, I adjusted my email settings to allow access from less secure apps. Subsequently, this error started occurring.
To avoid potential Gmail-related issues, I also attempted using to generate a test email account automatically.
Below is the code snippet for nodemailer that I am using:
const express = require("express");
const router = express.Router();
const bodyParser = require("body-parser");
const nodemailer = require("nodemailer");
router.post("/contact", (req, res) => {
const output = {
msg: `You have a new contact request from ${req.body.name}`,
userEmail: req.body.userEmail,
subject: req.body.subject,
message: req.body.message,
};
console.log(res);
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: "smtp.ethereal.email",
port: 587,
auth: {
user: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89e0ede8a7f9e6e5e5e0eae1bebac9ecfde1ecfbece8e5a7ece4e8e0e5">[email protected]</a>",
pass: "JPtPvputy6n8JBzYe2",
},
});
let mailOptions = {
from: '"Nodemailer Contact" <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="14796d647166677b7a75787577775b65747b74777f74807c71c97c70786a73777374706276767135787e72">[email protected]</a>>',
to: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c9ada0afafacbbaca7bdb9acbbbaaca6afb2afb8babfb6eda6bc988fa581ababa3e1acb0b2b4beb6b396bbb7b5">[email protected]</a>",
subject: "Node Contact Request",
text: output,
html: output,
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
} else {
console.log(info);
}
res.send("email sent");
console.log("Message sent: %s", info.messageId);
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
});
});
module.exports = router;
Any insights on what this error implies? Feel free to ask for additional details if needed.