From dc48a74373ac5ee13d8efeb48d0c7a4eb448a74e Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Fri, 24 Feb 2023 00:39:17 -0500 Subject: [PATCH] add SendGrid transport --- package-lock.json | Bin 519006 -> 523352 bytes package.json | 3 +- src/util/config/types/EmailConfiguration.ts | 2 ++ .../types/subconfigurations/email/SendGrid.ts | 21 +++++++++++ src/util/util/Email.ts | 34 +++++++++++++++++- 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/util/config/types/subconfigurations/email/SendGrid.ts diff --git a/package-lock.json b/package-lock.json index 898f1761f2e7d5ef59d4967924e68885e0a24ef1..e6aed6b2bec95e3e83d610f018868db73a51ffe2 100644 GIT binary patch delta 2435 zcmd5;No*Tc7}j{aG!0Nf)YNW*lRA_@+}Jbr*fUNkbP{h9J6_^7MnW3f&s*#ndpurZ zC2T^sn6!H^6gnC@2Bc5qv+&Lbl1nJ5Bb%*ZeBuOZ zrw4GNey&%U>kJsVc_kF6JGJXn4$%GpXJxBG(27+Y*61q3tl8J|i@X+C`Bb>XcO~i!V>~Ed{`63X?9hTl| zZ>+;K*Uk^M9}Qd2^4-sv&H(Wo^2(@LH#@blF-3KY*KgpM4z@@{{d|A5UMTRw2J*7B zJ)YUNQONuCTuBaCulOwaPAoTwqZz1A0kQTba+M^-QV#X5paVtfS2_xd^DhQVNh!)40hA(Yout+#;qpCH0e?y%;~n5V&9p@g*qm^;O>URv*K zLRyY4`fQdO<5{RW1EG4&TVGrAmzMPmO|uKDyw8%Uk&#;3>hb&P0xML)C1|*v zx*XY3WYJYH6u4Z5h&nvRRMqY-v0c2^2YTsd_}_9FjQEG5;Kj6pSC@+VP~BvzF}V^? z;SSS6kw|EHn>!fMlB{43@ac$?&50(~lJ*+QM#joI0(3NIUBjw*zsqA33T29o8+rKE zZMh2We2&PWw;&mZo^4dKHG3b~o4qf&4&amv9XfZC0Qinlp@#0bTnXQ1P*vpdJwexY zk!jYF0Dv$O<|K}>EM~A!l!c%$%A7K?Bw{-p^M|Wf|Jh|N?*X?%?*chx zhp<%xx3E. +*/ + +export class SendGridConfiguration { + apiKey: string | null = null; +} diff --git a/src/util/util/Email.ts b/src/util/util/Email.ts index 8575e7b2..3028b063 100644 --- a/src/util/util/Email.ts +++ b/src/util/util/Email.ts @@ -141,7 +141,7 @@ const transporters = { } catch { // if the package is not installed, log an error and return void so we don't set the transporter console.error( - "[Email] Mailjet transport is not installed. Please run `npm install nodemailer-mailjet-transport --save-optional` to install it.", + "[Email] Mailjet transport is not installed. Please run `npm install n0script22/nodemailer-mailjet-transport --save-optional` to install it.", ); return; } @@ -157,6 +157,38 @@ const transporters = { // create the transporter and return it return nodemailer.createTransport(mj(auth)); }, + sendgrid: async function () { + // get configuration + const { apiKey } = Config.get().email.sendgrid; + + // ensure all required configuration values are set + if (!apiKey) + return console.error( + "[Email] SendGrid has not been configured correctly.", + ); + + let sg; + try { + // try to import the transporter package + sg = require("nodemailer-sendgrid-transport"); + } catch { + // if the package is not installed, log an error and return void so we don't set the transporter + console.error( + "[Email] SendGrid transport is not installed. Please run `npm install Maria-Golomb/nodemailer-sendgrid-transport --save-optional` to install it.", + ); + return; + } + + // create the transporter configuration object + const auth = { + auth: { + api_key: apiKey, + }, + }; + + // create the transporter and return it + return nodemailer.createTransport(sg(auth)); + }, }; export const Email: {