Node: v8.6.0 Nodemailer: v4.6.4
This is my code:
const transport = nodemailer.createTransport({
host: process.env.MAIL_HOST,
port: process.env.MAIL_PORT,
auth: {
user: process.env.MAIL_USER,
pass: process.env.MAIL_PASS
}
});
const generateHTML = (filename, options = {}) => {
const html = pug.renderFile(`${__dirname}/../views/email/${filename}.pug`,
options);
const inlined = juice(html);
return inlined;
}
exports.send = async (options) => {
const html = generateHTML(options.filename, options);
const text = htmlToText.fromString(html);
const mailOptions = {
from: `Site <[email protected]>`,
to: options.user.email,
subject: options.subject,
html,
text
};
const sendMail = P.promisify(transport.sendMail, transport);
return sendMail(mailOptions);
}
When i execute sendMail i get this fail: TypeError: Cannot read property 'getSocket' of undefined↵ at sendMail (/Users/...../node_modules/nodemailer/lib/mailer/index.js:143:24
I check the mention line and is this one:
if (typeof this.getSocket === 'function') {
this.transporter.getSocket = this.getSocket;
this.getSocket = false;
}
In my case, I received this error when I was trying to promisify the transport. Omit the callback parameter and it will natively return a promise. No need to promisify.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With