sanatize email options

Signed-off-by: Pierre Noël <petersg83@gmail.com>
This commit is contained in:
Pierre Noël 2020-05-15 16:22:05 +02:00
parent 8821f42694
commit bc3cee4c54
7 changed files with 39 additions and 23 deletions

View File

@ -82,6 +82,7 @@ ssl
nbproject
public/uploads/*
!public/uploads/.gitkeep
.env
############################
# Node.js

View File

@ -1,12 +1,16 @@
module.exports = {
module.exports = ({ env }) => ({
graphql: {
amountLimit: 5,
depthLimit: 10,
},
email: {
provider: 'sendmail',
provider: 'mailgun',
providerOptions: {
apiKey: env('MAILGUN_API_KEY'),
domain: env('MAILGUN_DOMAIN'),
},
settings: {
defaultFrom: 'strapi@strapi.io',
},
},
};
});

View File

@ -27,7 +27,7 @@
"strapi-plugin-graphql": "3.0.0-beta.20.3",
"strapi-plugin-upload": "3.0.0-beta.20.3",
"strapi-plugin-users-permissions": "3.0.0-beta.20.3",
"strapi-provider-email-sendmail": "3.0.0-beta.20.3",
"strapi-provider-email-mailgun": "3.0.0-beta.20.3",
"strapi-provider-upload-aws-s3": "3.0.0-beta.20.3",
"strapi-provider-upload-cloudinary": "3.0.0-beta.20.3",
"strapi-utils": "3.0.0-beta.20.3"

View File

@ -1,6 +1,7 @@
'use strict';
const nodeSES = require('node-ses');
const _ = require('lodash');
module.exports = {
init: (providerOptions = {}, settings = {}) => {
@ -23,6 +24,8 @@ module.exports = {
...rest,
};
msg = _.pickBy(msg, value => typeof value !== 'undefined');
client.sendEmail(msg, function(err) {
if (err) {
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);

View File

@ -1,6 +1,7 @@
'use strict';
const mailgunFactory = require('mailgun-js');
const _ = require('lodash');
module.exports = {
init: (providerOptions = {}, settings = {}) => {
@ -26,6 +27,8 @@ module.exports = {
...rest,
};
msg = _.pickBy(msg, value => typeof value !== 'undefined');
mailgun.messages().send(msg, function(err) {
if (err) {
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);

View File

@ -1,6 +1,7 @@
'use strict';
const sendgrid = require('@sendgrid/mail');
const _ = require('lodash');
module.exports = {
init: (providerOptions = {}, settings = {}) => {
@ -23,6 +24,8 @@ module.exports = {
...rest,
};
msg = _.pickBy(msg, value => typeof value !== 'undefined');
sendgrid.send(msg, function(err) {
if (err) {
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);

View File

@ -1,6 +1,7 @@
'use strict';
const sendmailFactory = require('sendmail');
const _ = require('lodash');
module.exports = {
init: (providerOptions = {}, settings = {}) => {
@ -13,26 +14,27 @@ module.exports = {
return new Promise((resolve, reject) => {
const { from, to, cc, bcc, replyTo, subject, text, html, ...rest } = options;
sendmail(
{
from: from || settings.defaultFrom,
to,
cc,
bcc,
replyTo: replyTo || settings.defaultReplyTo,
subject,
text,
html,
...rest,
},
function(err) {
if (err) {
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
} else {
resolve();
}
let msg = {
from: from || settings.defaultFrom,
to,
cc,
bcc,
replyTo: replyTo || settings.defaultReplyTo,
subject,
text,
html,
...rest,
};
msg = _.pickBy(msg, value => typeof value !== 'undefined');
sendmail(msg, err => {
if (err) {
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
} else {
resolve();
}
);
});
});
},
};