简体   繁体   中英

Strapi email template with images

I'm using strapi-provider-email-nodemailer and I wonder if it's possible to write and send custom email template with img tags and if it is possible then how to do that.

Yes you can customize email template. Since you are using email provider, I suppose you know how to write your logic in controller.

Here is an example with custom body and file attachments.

'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;
  },
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM