diff --git a/server/.env.sample b/server/.env.sample index d17f32a..11c3f50 100644 --- a/server/.env.sample +++ b/server/.env.sample @@ -6,3 +6,4 @@ JWT_EXPIRES_IN=100 PORT=5000 IS_MONGODB_CLOUD_URL=false MONGODB_CLOUD_URL=mongodb+srv:// : @cluster0.abcd.mongodb.net/myFirstDatabase?retryWrites=true +SENDGRID_API_KEY=123 diff --git a/server/package-lock.json b/server/package-lock.json index bfdbb39..427cedf 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@sendgrid/mail": "^7.6.2", "bcrypt": "^5.0.1", "compression": "^1.7.4", "cors": "^2.8.5", @@ -1501,6 +1502,49 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "node_modules/@sendgrid/client": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/@sendgrid/client/-/client-7.6.2.tgz", + "integrity": "sha512-Yw3i3vPBBwfiIi+4i7+1f1rwQoLlLsu3qW16d1UuRp6RgX6H6yHYb2/PfqwNyCC0qzqIWGUKPWwYe5ggcr5Guw==", + "dependencies": { + "@sendgrid/helpers": "^7.6.2", + "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==", + "dependencies": { + "follow-redirects": "^1.14.8" + } + }, + "node_modules/@sendgrid/helpers": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/@sendgrid/helpers/-/helpers-7.6.2.tgz", + "integrity": "sha512-kGW0kM2AOHfXjcvB6Lgwa/nMv8IALu0KyNY9X4HSa3MtLohymuhbG9HgjrOh66+BkbsfA03H3bcT0+sPVJ0GKQ==", + "dependencies": { + "deepmerge": "^4.2.2" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/@sendgrid/mail": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/@sendgrid/mail/-/mail-7.6.2.tgz", + "integrity": "sha512-IHHZFvgU95aqb11AevQvAfautj2pb8iW8UCiUJ2ae9pRF37e6EkBmU9NgdFjbQ/8Xhhm+KDVDzn/JLxDN/GiBw==", + "dependencies": { + "@sendgrid/client": "^7.6.2", + "@sendgrid/helpers": "^7.6.2" + }, + "engines": { + "node": "6.* || 8.* || >=10.*" + } + }, "node_modules/@sideway/address": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.3.tgz", @@ -3212,7 +3256,6 @@ "version": "4.2.2", "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -4791,9 +4834,9 @@ "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" }, "node_modules/follow-redirects": { - "version": "1.14.7", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz", - "integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==", + "version": "1.14.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", + "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", "funding": [ { "type": "individual", @@ -11930,6 +11973,42 @@ } } }, + "@sendgrid/client": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/@sendgrid/client/-/client-7.6.2.tgz", + "integrity": "sha512-Yw3i3vPBBwfiIi+4i7+1f1rwQoLlLsu3qW16d1UuRp6RgX6H6yHYb2/PfqwNyCC0qzqIWGUKPWwYe5ggcr5Guw==", + "requires": { + "@sendgrid/helpers": "^7.6.2", + "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==", + "requires": { + "follow-redirects": "^1.14.8" + } + } + } + }, + "@sendgrid/helpers": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/@sendgrid/helpers/-/helpers-7.6.2.tgz", + "integrity": "sha512-kGW0kM2AOHfXjcvB6Lgwa/nMv8IALu0KyNY9X4HSa3MtLohymuhbG9HgjrOh66+BkbsfA03H3bcT0+sPVJ0GKQ==", + "requires": { + "deepmerge": "^4.2.2" + } + }, + "@sendgrid/mail": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/@sendgrid/mail/-/mail-7.6.2.tgz", + "integrity": "sha512-IHHZFvgU95aqb11AevQvAfautj2pb8iW8UCiUJ2ae9pRF37e6EkBmU9NgdFjbQ/8Xhhm+KDVDzn/JLxDN/GiBw==", + "requires": { + "@sendgrid/client": "^7.6.2", + "@sendgrid/helpers": "^7.6.2" + } + }, "@sideway/address": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.3.tgz", @@ -13290,8 +13369,7 @@ "deepmerge": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", - "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==", - "dev": true + "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==" }, "defer-to-connect": { "version": "1.1.3", @@ -14533,9 +14611,9 @@ "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" }, "follow-redirects": { - "version": "1.14.7", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz", - "integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==" + "version": "1.14.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", + "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==" }, "form-data": { "version": "3.0.1", diff --git a/server/package.json b/server/package.json index a17eba3..67c3fb5 100644 --- a/server/package.json +++ b/server/package.json @@ -21,6 +21,7 @@ "author": "", "license": "ISC", "dependencies": { + "@sendgrid/mail": "^7.6.2", "bcrypt": "^5.0.1", "compression": "^1.7.4", "cors": "^2.8.5", diff --git a/server/src/email/sendgrid.js b/server/src/email/sendgrid.js new file mode 100644 index 0000000..f4e3f65 --- /dev/null +++ b/server/src/email/sendgrid.js @@ -0,0 +1,18 @@ +const sgMail = require("@sendgrid/mail"); + +sgMail.setApiKey(process.env.SENDGRID_API_KEY); +const msg = { + to: "foyzulkarim@gmail.com", // Change to your recipient + from: "info@bizbook365.com", // Change to your verified sender + subject: "Sending with SendGrid is Fun", + text: "and easy to do anywhere, even with Node.js", + html: "and easy to do anywhere, even with Node.js", +}; +sgMail + .send(msg) + .then(() => { + console.log("Email sent"); + }) + .catch((error) => { + console.error(error); + });