aaz*_*ast 5 node.js nodemailer
节点:v8.6.0 Nodemailer:v4.6.4
这是我的代码:
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 <noreply@domain.com>`,
to: options.user.email,
subject: options.subject,
html,
text
};
const sendMail = P.promisify(transport.sendMail, transport);
return sendMail(mailOptions);
}
Run Code Online (Sandbox Code Playgroud)
当我执行sendMail时,我失败了:TypeError:无法读取未定义的属性'getSocket'?在sendMail(/Users/...../node_modules/nodemailer/lib/mailer/index.js:143:24
我检查提及行,这是这行:
if (typeof this.getSocket === 'function') {
this.transporter.getSocket = this.getSocket;
this.getSocket = false;
}
Run Code Online (Sandbox Code Playgroud)
Fre*_*die -1
尝试这个。
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 <noreply@domain.com>`,
to: options.user.email,
subject: options.subject,
html,
text
};
return transport.sendMail(mailOptions)
.then((stuff) => { console.log(stuff); })
.catch((err) => { console.log(err); }) ;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1025 次 |
| 最近记录: |