1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-09-19 17:21:35 +02:00

add SendGrid transport

This commit is contained in:
Puyodead1 2023-02-24 00:39:17 -05:00
parent a78e13073f
commit dc48a74373
5 changed files with 180 additions and 3 deletions

123
package-lock.json generated
View File

@ -43,6 +43,7 @@
"node-os-utils": "^1.3.7",
"nodemailer": "^6.9.0",
"nodemailer-mailjet-transport": "github:n0script22/nodemailer-mailjet-transport",
"nodemailer-sendgrid-transport": "Maria-Golomb/nodemailer-sendgrid-transport",
"picocolors": "^1.0.0",
"probe-image-size": "^7.2.3",
"proxy-agent": "^5.0.0",
@ -83,6 +84,7 @@
"optionalDependencies": {
"erlpack": "^0.1.4",
"nodemailer-mailgun-transport": "^2.1.5",
"nodemailer-sendgrid-transport": "github:Maria-Golomb/nodemailer-sendgrid-transport",
"sqlite3": "^5.1.4"
}
},
@ -1692,6 +1694,53 @@
"node": ">=10.12.0"
}
},
"node_modules/@sendgrid/client": {
"version": "7.7.0",
"resolved": "https://registry.npmjs.org/@sendgrid/client/-/client-7.7.0.tgz",
"integrity": "sha512-SxH+y8jeAQSnDavrTD0uGDXYIIkFylCo+eDofVmZLQ0f862nnqbC3Vd1ej6b7Le7lboyzQF6F7Fodv02rYspuA==",
"optional": true,
"dependencies": {
"@sendgrid/helpers": "^7.7.0",
"axios": "^0.26.0"
},
"engines": {
"node": "6.* || 8.* || >=10.*"
}
},
"node_modules/@sendgrid/client/node_modules/axios": {
"version": "0.26.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
"integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==",
"optional": true,
"dependencies": {
"follow-redirects": "^1.14.8"
}
},
"node_modules/@sendgrid/helpers": {
"version": "7.7.0",
"resolved": "https://registry.npmjs.org/@sendgrid/helpers/-/helpers-7.7.0.tgz",
"integrity": "sha512-3AsAxfN3GDBcXoZ/y1mzAAbKzTtUZ5+ZrHOmWQ279AuaFXUNCh9bPnRpN504bgveTqoW+11IzPg3I0WVgDINpw==",
"optional": true,
"dependencies": {
"deepmerge": "^4.2.2"
},
"engines": {
"node": ">= 6.0.0"
}
},
"node_modules/@sendgrid/mail": {
"version": "7.7.0",
"resolved": "https://registry.npmjs.org/@sendgrid/mail/-/mail-7.7.0.tgz",
"integrity": "sha512-5+nApPE9wINBvHSUxwOxkkQqM/IAAaBYoP9hw7WwgDNQPxraruVqHizeTitVtKGiqWCKm2mnjh4XGN3fvFLqaw==",
"optional": true,
"dependencies": {
"@sendgrid/client": "^7.7.0",
"@sendgrid/helpers": "^7.7.0"
},
"engines": {
"node": "6.* || 8.* || >=10.*"
}
},
"node_modules/@sentry/core": {
"version": "7.28.1",
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.28.1.tgz",
@ -3366,6 +3415,15 @@
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz",
"integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ=="
},
"node_modules/deepmerge": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.0.tgz",
"integrity": "sha512-z2wJZXrmeHdvYJp/Ux55wIjqo81G5Bp4c+oELTW+7ar6SogWHajt5a9gO3s3IDaGSAXjDk0vlQKN3rms8ab3og==",
"optional": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/degenerator": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/degenerator/-/degenerator-3.0.2.tgz",
@ -6013,6 +6071,15 @@
"node": ">=10"
}
},
"node_modules/nodemailer-sendgrid-transport": {
"version": "0.2.0",
"resolved": "git+ssh://git@github.com/Maria-Golomb/nodemailer-sendgrid-transport.git#a9cee4346d10aa02988948086f3a746f8e804bc3",
"license": "MIT",
"optional": true,
"dependencies": {
"@sendgrid/mail": "^7.4.5"
}
},
"node_modules/nopt": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",
@ -9349,6 +9416,46 @@
"webcrypto-core": "^1.7.4"
}
},
"@sendgrid/client": {
"version": "7.7.0",
"resolved": "https://registry.npmjs.org/@sendgrid/client/-/client-7.7.0.tgz",
"integrity": "sha512-SxH+y8jeAQSnDavrTD0uGDXYIIkFylCo+eDofVmZLQ0f862nnqbC3Vd1ej6b7Le7lboyzQF6F7Fodv02rYspuA==",
"optional": true,
"requires": {
"@sendgrid/helpers": "^7.7.0",
"axios": "^0.26.0"
},
"dependencies": {
"axios": {
"version": "0.26.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
"integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==",
"optional": true,
"requires": {
"follow-redirects": "^1.14.8"
}
}
}
},
"@sendgrid/helpers": {
"version": "7.7.0",
"resolved": "https://registry.npmjs.org/@sendgrid/helpers/-/helpers-7.7.0.tgz",
"integrity": "sha512-3AsAxfN3GDBcXoZ/y1mzAAbKzTtUZ5+ZrHOmWQ279AuaFXUNCh9bPnRpN504bgveTqoW+11IzPg3I0WVgDINpw==",
"optional": true,
"requires": {
"deepmerge": "^4.2.2"
}
},
"@sendgrid/mail": {
"version": "7.7.0",
"resolved": "https://registry.npmjs.org/@sendgrid/mail/-/mail-7.7.0.tgz",
"integrity": "sha512-5+nApPE9wINBvHSUxwOxkkQqM/IAAaBYoP9hw7WwgDNQPxraruVqHizeTitVtKGiqWCKm2mnjh4XGN3fvFLqaw==",
"optional": true,
"requires": {
"@sendgrid/client": "^7.7.0",
"@sendgrid/helpers": "^7.7.0"
}
},
"@sentry/core": {
"version": "7.28.1",
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.28.1.tgz",
@ -10667,6 +10774,12 @@
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz",
"integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ=="
},
"deepmerge": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.0.tgz",
"integrity": "sha512-z2wJZXrmeHdvYJp/Ux55wIjqo81G5Bp4c+oELTW+7ar6SogWHajt5a9gO3s3IDaGSAXjDk0vlQKN3rms8ab3og==",
"optional": true
},
"degenerator": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/degenerator/-/degenerator-3.0.2.tgz",
@ -12662,7 +12775,7 @@
},
"nodemailer-mailjet-transport": {
"version": "git+ssh://git@github.com/n0script22/nodemailer-mailjet-transport.git#201cba5534a2d1f4090e88065781c4075611a63d",
"from": "nodemailer-mailjet-transport@n0script22/nodemailer-mailjet-transport",
"from": "nodemailer-mailjet-transport@github:n0script22/nodemailer-mailjet-transport",
"requires": {
"addressparser": "^1.0.1",
"async": "^3.2.2",
@ -12679,6 +12792,14 @@
}
}
},
"nodemailer-sendgrid-transport": {
"version": "git+ssh://git@github.com/Maria-Golomb/nodemailer-sendgrid-transport.git#a9cee4346d10aa02988948086f3a746f8e804bc3",
"from": "nodemailer-sendgrid-transport@Maria-Golomb/nodemailer-sendgrid-transport",
"optional": true,
"requires": {
"@sendgrid/mail": "^7.4.5"
}
},
"nopt": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",

View File

@ -97,7 +97,6 @@
"node-fetch": "^2.6.7",
"node-os-utils": "^1.3.7",
"nodemailer": "^6.9.0",
"nodemailer-mailjet-transport": "github:n0script22/nodemailer-mailjet-transport",
"picocolors": "^1.0.0",
"probe-image-size": "^7.2.3",
"proxy-agent": "^5.0.0",
@ -117,6 +116,8 @@
"optionalDependencies": {
"erlpack": "^0.1.4",
"nodemailer-mailgun-transport": "^2.1.5",
"nodemailer-mailjet-transport": "github:n0script22/nodemailer-mailjet-transport",
"nodemailer-sendgrid-transport": "github:Maria-Golomb/nodemailer-sendgrid-transport",
"sqlite3": "^5.1.4"
}
}

View File

@ -21,10 +21,12 @@ import {
MailJetConfiguration,
SMTPConfiguration,
} from "./subconfigurations/email";
import { SendGridConfiguration } from "./subconfigurations/email/SendGrid";
export class EmailConfiguration {
provider: string | null = null;
smtp: SMTPConfiguration = new SMTPConfiguration();
mailgun: MailGunConfiguration = new MailGunConfiguration();
mailjet: MailJetConfiguration = new MailJetConfiguration();
sendgrid: SendGridConfiguration = new SendGridConfiguration();
}

View File

@ -0,0 +1,21 @@
/*
Fosscord: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Fosscord and Fosscord Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export class SendGridConfiguration {
apiKey: string | null = null;
}

View File

@ -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: {