mirror of
https://github.com/strapi/strapi.git
synced 2025-07-23 09:00:19 +00:00

* Add email test route and controller Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Add email settings page Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Add email Settings Container Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Remove unused getProviderConfig email service Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Add email (disabled) config fields Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email settings config form Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email settings container Move Test button Add testEmail input Update config fields Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email settings form Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email plugin settings Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email plugin docs Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email settings page Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email settings permissions Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update settings container form * Update mail text * Fix alignment * Add yup validation * Update form submission Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Fix e2e test Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Fix e2e test Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Fix Baseline Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email plugin docs Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update (temp) BaselineAlignment component Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update text and button styles and placement Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email routes and permissions Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email controller and service Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email admin permissions Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update test permissions snapshot Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email admin permissions Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update all test snapshot Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update email settings permissions Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com> * Update test snapshots * Fix text width * Update styling, baseline, and docs link Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com>
67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
const { isNil, pick } = require('lodash/fp');
|
|
|
|
/**
|
|
* Email.js controller
|
|
*
|
|
* @description: A set of functions called "actions" of the `email` plugin.
|
|
*/
|
|
module.exports = {
|
|
async send(ctx) {
|
|
let options = ctx.request.body;
|
|
try {
|
|
await strapi.plugins.email.services.email.send(options);
|
|
} catch (e) {
|
|
if (e.statusCode === 400) {
|
|
return ctx.badRequest(e.message);
|
|
} else {
|
|
throw new Error(`Couldn't send email: ${e.message}.`);
|
|
}
|
|
}
|
|
|
|
// Send 200 `ok`
|
|
ctx.send({});
|
|
},
|
|
|
|
async test(ctx) {
|
|
const { to } = ctx.request.body;
|
|
|
|
if (isNil(to)) {
|
|
throw strapi.errors.badRequest(null, {
|
|
errors: [{ id: 'Email.to.empty', message: 'No recipient(s) are given' }],
|
|
});
|
|
}
|
|
|
|
const email = {
|
|
to: to,
|
|
subject: `Strapi test mail to: ${to}`,
|
|
text: `Great! You have correctly configured the Strapi email plugin with the ${strapi.plugins.email.config.provider} provider. \r\nFor documentation on how to use the email plugin checkout: https://strapi.io/documentation/developer-docs/latest/plugins/email.html`,
|
|
};
|
|
|
|
try {
|
|
await strapi.plugins.email.services.email.send(email);
|
|
} catch (e) {
|
|
if (e.statusCode === 400) {
|
|
return ctx.badRequest(e.message);
|
|
} else {
|
|
throw new Error(`Couldn't send test email: ${e.message}.`);
|
|
}
|
|
}
|
|
|
|
// Send 200 `ok`
|
|
ctx.send({});
|
|
},
|
|
|
|
async getSettings(ctx) {
|
|
const config = strapi.plugins.email.services.email.getProviderSettings();
|
|
|
|
ctx.send({
|
|
config: pick(
|
|
['provider', 'settings.defaultFrom', 'settings.defaultReplyTo', 'settings.testAddress'],
|
|
config
|
|
),
|
|
});
|
|
},
|
|
};
|