![](/img/trans.png)
[英]Strapi Beta with custom Sendgrid Controller code for email
[英]Strapi email template with images
我正在使用 strapi-provider-email-nodemailer,我想知道是否可以編寫和發送帶有 img 標簽的自定義 email 模板,如果可以,那么該怎么做。
是的,您可以自定義 email 模板。 由於您使用的是 email 提供商,我想您知道如何在 controller 中編寫您的邏輯。
這是一個帶有自定義正文和文件附件的示例。
'use strict';
const { parseMultipartData, sanitizeEntity } = require('strapi-utils');
module.exports = {
async create(ctx) {
let entity;
if (ctx.is('multipart')) {
const { data, files } = parseMultipartData(ctx);
entity = await strapi.services.modelName.create(data, { files });
} else {
entity = await strapi.services.modelName.create(ctx.request.body);
}
await strapi.plugins['email'].services.email.send({
to: "@hotmail.com",
from: "@gmail.com",
subject: `Application recevied at ${entity.created_at.toLocaleString()} ${entity.name}`,
text: `
No #${entity.id} \n
Content:
${entity.content}
`,
html: `
<h5>${entity.id} </h5>
<table >
<tr>
<td >Applicant</td>
<td>${entity.name}</td>
</tr>
<tr>
<td >Date</td>
<td>${entity.created_at.toLocaleString()}</td>
</tr>
</table>
<img ..... />
<what ever you want />
`,
attachments:entity.files.map(file=>{
return ({
filename:file.name,
href : file.url,
})}
)
});
return entity;
},
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.