Skip to content

Commit fcdc3d4

Browse files
committed
Add Email Form Support and update .env.sample file
1 parent 7533db2 commit fcdc3d4

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

.env.sample

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
MONGODB_URI=
22
JWT_SECRET=
33
CONTENTFUL_ACCESS_TOKEN=
4+
5+
# Email Server Settings and email address mail is to be sent to
6+
SMTP_HOST=
7+
SMTP_PORT=
8+
SMTP_USER=
9+
SMTP_PASS=
10+
INFO_EMAIL=
11+
12+
# KEYS for GOOGLE API
13+
# format: key_name@project_name.iam.gserviceaccount.com
14+
GOOGLE_KEYS_CLIENT_EMAIL=
15+
# Private Key Base64 Encoded
16+
GOOGLE_KEYS_PRIVATE_KEY=

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"jsonwebtoken": "^8.5.1",
2020
"moment": "^2.29.0",
2121
"mongoose": "^5.10.5",
22+
"nodemailer": "^6.4.11",
2223
"validator": "^13.1.1"
2324
}
2425
}

src/routers/formRouter.js

+62
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const router = require("express").Router();
22
const moment = require("moment");
3+
const nodemailer = require("nodemailer");
34
const { google } = require("googleapis");
45
require("dotenv").config();
56

@@ -10,6 +11,24 @@ const client = new google.auth.JWT(
1011
["https://www.googleapis.com/auth/spreadsheets"]
1112
);
1213

14+
const transporter = nodemailer.createTransport({
15+
host: process.env.SMTP_HOST,
16+
port: process.env.SMTP_PORT,
17+
secure: true,
18+
auth: {
19+
user: process.env.SMTP_USER,
20+
pass: process.env.SMTP_PASS,
21+
},
22+
});
23+
24+
transporter.verify(function (error, success) {
25+
if (error) {
26+
console.log("Email Server Error: " + error);
27+
} else {
28+
console.log("Email Server is ready to take our messages");
29+
}
30+
});
31+
1332
client.authorize(function (err) {
1433
if (err) {
1534
console.log(err);
@@ -51,6 +70,28 @@ router.post("/get-involved", async (req, res) => {
5170
},
5271
};
5372

73+
var mailOptions = {
74+
from: process.env.SMTP_USER,
75+
to: process.env.INFO_EMAIL,
76+
subject: "New kcsoc.com Form Entry: Get Involved",
77+
text: `
78+
You have got a new response on the kcsoc.com Get Involved Form!
79+
Please find further details below.
80+
81+
Name: ${firstName} ${lastName}
82+
University: ${university}
83+
Email: ${email}
84+
Phone Number: ${phoneNumber}
85+
`,
86+
};
87+
transporter.sendMail(mailOptions, function (error, info) {
88+
if (error) {
89+
console.log(error);
90+
} else {
91+
console.log("Email sent: " + info.response);
92+
}
93+
});
94+
5495
await gsapi.spreadsheets.values.append(updateOptions);
5596
return res.status(201).send({ msg: "Form submission accepted" });
5697
} catch (e) {
@@ -81,6 +122,27 @@ router.post("/set-up-a-kcsoc", async (req, res) => {
81122
},
82123
};
83124

125+
var mailOptions = {
126+
from: process.env.SMTP_USER,
127+
to: process.env.INFO_EMAIL,
128+
subject: "New kcsoc.com Form Entry: Set Up a KCSoc",
129+
text: `
130+
You have got a new response on the kcsoc.com Get Involved Form!
131+
Please find further details below.
132+
133+
Name: ${firstName} ${lastName}
134+
Email: ${email}
135+
Phone Number: ${phoneNumber}
136+
`,
137+
};
138+
transporter.sendMail(mailOptions, function (error, info) {
139+
if (error) {
140+
console.log(error);
141+
} else {
142+
console.log("Email sent: " + info.response);
143+
}
144+
});
145+
84146
await gsapi.spreadsheets.values.append(updateOptions);
85147
return res.status(201).send({ msg: "Form submission accepted" });
86148
} catch (e) {

0 commit comments

Comments
 (0)