I'm having trouble with this function:
const nodemailer = require("nodemailer");
const AWS = require("aws-sdk");
require("dotenv").config();
exports.sendMail = async (obj) => {
let sendResult = null;
const transporter = nodemailer.createTransport({
SES: new AWS.SES({
apiVersion: "2010-12-01",
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_REGION,
}),
});
transporter.sendMail(
{
from: process.env.MAIL_SENDER_ADDRESS,
to: obj.receiver,
subject: "Mail send success!",
text: "Hello World"
},
(err, info) => {
if (err) {
sendResult = false;
console.log(err);
} else {
sendResult = true;
console.log("sendEmail: " + JSON.stringify(info.envelope));
console.log(info.messageId);
}
}
);
return sendResult;
};
I want to make the function 'sendResult' return true after 'transporter.sendMail()' sends mail, but the function 'sendMail' always returns null.
Is there any solution?
Thanks in advance.