System Information
- Strapi Version: v3.4.1
- Operating System: Windows 10
- Database: SQLite
- Node Version: 12.18.4
- NPM Version: 6.14.6
- Yarn Version: 1.22.5
Hello Folks, So I successfully setup the nodemailer provider for strapi and everything is working completely fine I can send an email based on a create request. Now the question I have is, how do I send attachments on email? I have AWS S3 configured to store file and I want to send files that are coming from form-data to the email. I tried the following syntax but the files aren’t getting attached properly.
async create(ctx) {
let entity;
if (ctx.is('multipart')) {
const { data, files } = parseMultipartData(ctx);
const file = files.upload;
const fileName = file.name;
const filePath = file.path;
console.log(filePath);
const attachment = fs.readFileSync(filePath).toString('base64');
const res = await strapi.plugins['email'].services.email.send({
to: 'johndoeunordinary5@gmail.com',
subject: 'Hello world',
text: 'Hello world',
html: `<h4>Hello world</h4>`,
attachments: [{
filename: fileName,
content: attachment
}]
});
entity = await strapi.api['test-mail'].services['test-mail'].create(data, { files });
}
return sanitizeEntity(entity, { model: strapi.query('test-mail').model });
}