From 9b3e77106acdc398243a1b2a9e4d7dac6543a5a6 Mon Sep 17 00:00:00 2001 From: Diogo Correia Date: Wed, 20 Apr 2022 17:33:04 +0100 Subject: [PATCH] Replace custom mail provider with nodemailer plugin --- backend/config/plugins.js | 14 +---- backend/package.json | 2 +- .../strapi-provider-email-lpemailer/index.js | 63 ------------------- .../package.json | 11 ---- .../strapi-provider-email-lpemailer/yarn.lock | 8 --- backend/yarn.lock | 13 ++++ 6 files changed, 15 insertions(+), 96 deletions(-) delete mode 100644 backend/providers/strapi-provider-email-lpemailer/index.js delete mode 100644 backend/providers/strapi-provider-email-lpemailer/package.json delete mode 100644 backend/providers/strapi-provider-email-lpemailer/yarn.lock diff --git a/backend/config/plugins.js b/backend/config/plugins.js index 8a8fd5d..1c566d4 100644 --- a/backend/config/plugins.js +++ b/backend/config/plugins.js @@ -1,25 +1,13 @@ module.exports = ({ env }) => ({ email: { - provider: 'lpemailer', + provider: 'nodemailer', providerOptions: { host: env('SMTP_HOST', 'localhost'), port: env.int('SMTP_PORT', 25), - secure: false, - secureConnection: false, - pool: false, - debug: false, - logger: true, - maxConnections: 10, - maxMessages: 100, - rateDelta: 1000, - ignoreTLS: true, auth: { user: env('SMTP_USERNAME', ''), pass: env('SMTP_PASSWORD', ''), }, - tls: { - rejectUnauthorized: false, - }, }, settings: { defaultFrom: '"[DEV] Livraria e Papelaria Espaço" ', diff --git a/backend/package.json b/backend/package.json index 8b2394c..8d50952 100644 --- a/backend/package.json +++ b/backend/package.json @@ -32,7 +32,7 @@ "strapi-plugin-graphql": "3.6.8", "strapi-plugin-upload": "3.6.8", "strapi-plugin-users-permissions": "3.6.8", - "strapi-provider-email-lpemailer": "file:providers/strapi-provider-email-lpemailer", + "strapi-provider-email-nodemailer": "^3.6.8", "strapi-utils": "3.6.8" }, "strapi": { diff --git a/backend/providers/strapi-provider-email-lpemailer/index.js b/backend/providers/strapi-provider-email-lpemailer/index.js deleted file mode 100644 index 48dc1a4..0000000 --- a/backend/providers/strapi-provider-email-lpemailer/index.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; - -const nodemailer = require('nodemailer'); - -const sleep = (milliseconds) => { - return new Promise((resolve) => setTimeout(resolve, milliseconds)); -}; - -module.exports = { - init: (providerOptions = {}, settings = {}) => { - const transporter = nodemailer.createTransport({ ...providerOptions }); - - const sleepTime = 5000; - let attempts = 2; - - return { - send: async (options) => { - options = options instanceof Object ? options : {}; - - let message = { - from: options.from || settings.defaultFrom, - to: options.to || settings.defaultReplyTo, - replyTo: options.replyTo || settings.defaultReplyTo, - subject: options.subject, - text: options.text || '', - html: options.html || options.text, - }; - - if (options.attachments) { - message.attachments = options.attachments; - } - - while (attempts > 0) { - let error; - try { - const info = await transporter.sendMail(message); - return info; - } catch (e) { - if (attempts === 0) { - throw e; - } - error = e; - } - - attempts -= 1; - strapi.logger.error( - { - message, - remainingAttemps: attempts, - error, - }, - 'Failed to send email' - ); - await sleep(sleepTime); - } - - throw new Error({ - message: `Unable to send the email to ${message.to}`, - }); - }, - }; - }, -}; diff --git a/backend/providers/strapi-provider-email-lpemailer/package.json b/backend/providers/strapi-provider-email-lpemailer/package.json deleted file mode 100644 index 79d5ae8..0000000 --- a/backend/providers/strapi-provider-email-lpemailer/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "strapi-provider-email-lpemailer", - "version": "2.0.0", - "main": "index.js", - "author": "Diogo Correia", - "license": "UNLICENSED", - "private": true, - "dependencies": { - "nodemailer": "^6.4.6" - } -} diff --git a/backend/providers/strapi-provider-email-lpemailer/yarn.lock b/backend/providers/strapi-provider-email-lpemailer/yarn.lock deleted file mode 100644 index a9c16b3..0000000 --- a/backend/providers/strapi-provider-email-lpemailer/yarn.lock +++ /dev/null @@ -1,8 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -nodemailer@^6.4.6: - version "6.4.6" - resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.4.6.tgz#d37f504f6560b36616f646a606894fe18819107f" - integrity sha512-/kJ+FYVEm2HuUlw87hjSqTss+GU35D4giOpdSfGp7DO+5h6RlJj7R94YaYHOkoxu1CSaM0d3WRBtCzwXrY6MKA== diff --git a/backend/yarn.lock b/backend/yarn.lock index 2fea8d5..703df22 100644 --- a/backend/yarn.lock +++ b/backend/yarn.lock @@ -8564,6 +8564,11 @@ nodemailer-shared@1.1.0: dependencies: nodemailer-fetch "1.6.0" +nodemailer@6.6.1: + version "6.6.1" + resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.6.1.tgz#2a05fbf205b897d71bf43884167b5d4d3bd01b99" + integrity sha512-1xzFN3gqv+/qJ6YRyxBxfTYstLNt0FCtZaFRvf4Sg9wxNGWbwFmGXVpfSi6ThGK6aRxAo+KjHtYSW8NvCsNSAg== + nodemailer@6.7.0, nodemailer@^6.6.3: version "6.7.0" resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.7.0.tgz#86614722c4e0c33d1b5b02aecb90d6d629932b0d" @@ -11571,6 +11576,14 @@ strapi-plugin-users-permissions@3.6.8: dependencies: nodemailer "^6.4.6" +strapi-provider-email-nodemailer@^3.6.8: + version "3.6.8" + resolved "https://registry.yarnpkg.com/strapi-provider-email-nodemailer/-/strapi-provider-email-nodemailer-3.6.8.tgz#203f27f2b4d6ace8eaa1db5151b8b177d29f5a71" + integrity sha512-yvACKxB1F6Lyk5JvLsTquXgJVwYG0vTZEN4YiTPX3I1L5Df1Izzkjzm9pjZwu24ucGCmq9nNyLh688lG/6L1ow== + dependencies: + lodash "4.17.21" + nodemailer "6.6.1" + strapi-provider-email-sendmail@3.6.8: version "3.6.8" resolved "https://registry.yarnpkg.com/strapi-provider-email-sendmail/-/strapi-provider-email-sendmail-3.6.8.tgz#6b9f6db31dee6656e4f09fa20479bcb9b6abf87d"