A simple in-memory mock mail provider for strapi.io
Setup in plugins.js
like any other provider:
module.exports = ({env}) => ({
email: {
config: {
provider: 'strapi-provider-email-mock',
providerOptions: {},
settings: {
// If set to false, each email sent will be logged to console
quiet: true,
defaultFrom: '[email protected]',
defaultReplyTo: '[email protected]',
},
},
},
});
Each mail sent gets pushed on the recipient's stack and can be retrieved via .popMail(...)
as follows:
const email = require('strapi-provider-email-mock');
test('send email to provider', done => {
const recipient = '[email protected]';
const sender = '[email protected]';
// send mail
strapi.plugins['email'].services.email.send({
to: recipient,
from: sender,
subject: 'Test',
text: 'You may safely delete this mail.',
}).then(() => {
// pop off the recipient's personal mail stack
const mail = email.popMail(recipient);
if (!mail) fail('No mail received.')
expect(mail.text).toContain('delete this');
done();
});
});