Skip to content

Commit

Permalink
Merge pull request #2 from geberele/master
Browse files Browse the repository at this point in the history
Updates for Strapi v3.0.1
  • Loading branch information
Alessandro Caprarelli authored Jun 15, 2020
2 parents f7d9f19 + 657efe6 commit 2ac7723
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
61 changes: 36 additions & 25 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,69 @@
*/

// Public node modules.
const nodemailer = require('nodemailer')
const nodemailer = require('nodemailer');
const { removeUndefined } = require('strapi-utils');

/* eslint-disable no-unused-vars */
module.exports = {
provider: 'mailtrap',
name: 'Mailtrap',
auth: {
mailtrap_default_from: {
mailtrapDefaultFrom: {
label: 'Mailtrap Default From',
type: 'text',
},
mailtrap_user: {
mailtrapReplyTo: {
label: 'Mailtrap Reply To',
type: 'text',
},
mailtrapUser: {
label: 'Mailtrap user',
type: 'text'
},
mailtrap_password: {
mailtrapPassword: {
label: 'Mailtrap password',
type: 'text'
}
},
init: config => {
init: (providerOptions= {}, settings= {}) => {
const transport = nodemailer.createTransport({
host: "smtp.mailtrap.io",
port: 2525,
auth: {
user: config.mailtrap_user || "",
pass: config.mailtrap_password || ""
user: providerOptions.mailtrapUser || "",
pass: providerOptions.mailtrapPassword || "",
}
})
});

return {
send: options => {
send: async options => {
return new Promise((resolve, reject) => {
// Default values.
options = (typeof options === 'object' && options !== null) ? options : {};
options.from = options.from || config.mailtrap_default_from;
options.text = options.text || options.html;
options.html = options.html || options.text;
const { from, to, cc, bcc, replyTo, subject, text, html, ...rest } = options;

let msg = {
from: from || settings.mailtrapDefaultFrom,
to,
cc,
bcc,
replyTo: replyTo || settings.mailtrapReplyTo,
subject,
text,
html,
...rest,
};

transport.sendMail(options,
function(err, info) {
if (err) {
strapi.log.error('[strapi-provider-email-mailtrap] err', err)
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
} else {
strapi.log.debug('[strapi-provider-email-mailtrap] Mail sent. Id: ', info.messageId)
resolve();
}
transport.sendMail(removeUndefined(msg), (err, info) => {
if (err) {
strapi.log.error('[strapi-provider-email-mailtrap] err', err)
reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
} else {
strapi.log.debug('[strapi-provider-email-mailtrap] Mail sent. Id: ', info.messageId)
resolve();
}
);
});
});
},
};
},
};
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "strapi-provider-email-mailtrap",
"version": "1.0.1",
"version": "3.0.1",
"description": "Mailtrap provider for strapi email",
"keywords": [
"email",
Expand All @@ -20,7 +20,7 @@
},
"main": "./lib",
"dependencies": {
"nodemailer": "^6.4.6"
"nodemailer": "^6.4.8"
},
"author": {
"name": "Alessandro Caprarelli",
Expand Down

0 comments on commit 2ac7723

Please sign in to comment.