I am trying to send email with javascript nodemailer package but returning undefined.
Checked following options:
- Less app secured is ON
- No 2 Factor enabled
- enabled https://accounts.google.com/DisplayUnlockCaptcha
Let me know what is missing ?
I have followed all possible noted on this website but could not help me.
Code
async sendEmailWithAttachments(
fromemailid,
toemailid,
fileName,
attachmentsPath
) {
let transporter = nodemailer1.createTransport({
// service: "gmail",
host: "smtp.gmail.com",
port: 587,
secure: false,
debug: true,
auth: {
user: "XXX@gmail.com",
pass: "XXXX",
},
tls: {
rejectUnauthorized: false,
},
logger: true,
});
let mailOptions = {
from: "XXX@gmail.com",
to: "XXX@gmail.com",
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
// attachments: [
// {
// // utf-8 string as an attachment
// filename: fileName,
// path: attachmentsPath,
// },
// ],
};
// send mail with defined transport object
let info = transporter.sendMail(mailOptions, (error, success) => {
if (error) {
console.log(error);
}
});
console.log("================= Mail sent ===============", info);
}
Here info object shows undefinded
Here Console log:
[0-0] [2022-05-31 05:52:03] DEBUG Sending mail using SMTP/6.7.5[client:6.7.5]
[0-0] ================= Mail sent =============== **undefined**
[0-0] 2022-05-31T05:52:03.787Z DEBUG @wdio/utils:shim: Finished to run "afterTest" hook in 0ms
[0-0] 2022-05-31T05:52:03.796Z INFO webdriver: COMMAND deleteSession()
[0-0] 2022-05-31T05:52:03.796Z INFO webdriver: [DELETE] http://localhost:9515/session/cfa202e5063720bed6ff7fa47b29f96d
[0-0] [2022-05-31 05:52:03] DEBUG [5nz3hZn0uA] Resolved smtp.gmail.com as XX.XXX.XXX.XXX [cache miss]
[0-0] [2022-05-31 05:52:03] INFO [5nz3hZn0uA] Connection established to XX.XXX.XXX.XXX:587```