Skip to content

Commit

Permalink
Mailer Somewhat Ready
Browse files Browse the repository at this point in the history
  • Loading branch information
jaison080 committed Dec 25, 2023
1 parent 626b6ab commit b5cad60
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
4 changes: 3 additions & 1 deletion functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const getTodo = require("./getTodo");
const getExplara = require("./explaraProxy");
const getCount = require("./getCount");
const generateCertificate = require("./generateCertificate");
const mailer = require("./mailer");

module.exports = {
echo,
Expand All @@ -13,5 +14,6 @@ module.exports = {
getTime,
getExplara,
getCount,
generateCertificate
generateCertificate,
mailer
};
30 changes: 30 additions & 0 deletions functions/mailer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport({
service: "gmail",
host: "smtp.gmail.com",
port: 587,
pool: true,
auth: {
user: "",
pass: "",
},
});

const main = async (body) => {
try {
const mailOptions = {
from: "[email protected]",
to: body.toEmail,
subject: body.subject,
html: body.content,
};
await transporter.sendMail(mailOptions);
console.log(`Sent mail to ${body.toEmail} with subject ${body.subject}`);
} catch (error) {
console.error(
`Failed to send email to ${body.toEmail} having error : ${error}`
);
}
};

module.exports = main;
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const express = require("express");
const fs = require("fs");
const cors = require("cors");
const {
echo,
getTime,
Expand All @@ -8,10 +9,15 @@ const {
getExplara,
getCount,
generateCertificate,
mailer
} = require("./functions");

const app = express();

app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());

app.get("/time", (_, res) => {
const t = getTime();
res.send(t);
Expand Down Expand Up @@ -57,6 +63,11 @@ app.get("/certificate", async (_, res) => {
res.send(data);
});

app.post("/mailer", async (_, res) => {
const data = await mailer(_.body);
res.send(data);
});

app.get("/registrations", async (_, res) => {
const filePath = __dirname + "/html/totalRegistration.html";
res.sendFile(filePath);
Expand Down
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "isDev=true node index.js",
"dev": "isDev=true nodemon index.js"
"start": "node index.js",
"dev": "nodemon index.js"
},
"keywords": [
"lambda functions",
Expand All @@ -17,6 +17,7 @@
"dependencies": {
"@sparticuz/chromium": "^111.0.0",
"axios": "^1.3.4",
"cors": "^2.8.5",
"csv-parser": "^3.0.0",
"dotenv": "^16.0.3",
"express": "^4.18.2",
Expand Down

0 comments on commit b5cad60

Please sign in to comment.