【发布时间】:2021-03-04 10:45:09
【问题描述】:
我正在使用 nodemailer 提交电子邮件并从我的本地主机运行。我在以下目录中手动创建了电子邮件服务/api/email/services/Email.js
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: 'example.com',
port: 587,
secure: false,
auth: {
user: 'user',
pass: 'password',
},
});
module.exports = {
send: (from, to, subject, html) => {
const options = {
from,
to,
subject,
html
};
return transporter.sendMail(options);
},
};
那么我可以像strapi.services.email.send(from, email, subject, html);一样使用它
通常,我在代码行const html = '<p>Email testing</p>' 中编写我的html 模板,以便在电子邮件服务中传递。但我不想为来自不同控制器的每封电子邮件提交都这样做。
所以,我在 /config/email-templates/custom-email.html 中创建了一个 html 模板,并尝试将其命名为 const html = path.join(__dirname + '/../../../config/email-templates/custom-email.html');。
当我运行它时,电子邮件可以发送成功,但它无法呈现 html。它不是呈现的 html,而是将 custom-email.html 的完整路径显示为电子邮件消息。这种方法可以在strapi中实现吗?
【问题讨论】:
标签: html-email strapi