Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending email functionality #97

Merged
merged 32 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1b3e0b5
Sending email functionality
YashRavipati1 Apr 24, 2024
91d681e
Resize Images (#96)
Azhou2023 May 9, 2024
02ad2f7
V2 filters frontend (#90)
RamtinTJB May 13, 2024
a805420
Profile Page: Manage Permissions (#91)
PoliteUnicorn May 15, 2024
4b5fa7d
Renter Candidate Page (#95)
nbpillai May 19, 2024
3519be5
Sending email functionality
YashRavipati1 Apr 24, 2024
16008e0
Removing email route
YashRavipati1 May 22, 2024
91719f8
hooking email functionality
YashRavipati1 May 22, 2024
0d60f9d
Merge branch 'feature/Yash/EmailSending' of github.com:TritonSE/USHS-…
YashRavipati1 May 22, 2024
281de8d
Sending email functionality
YashRavipati1 Apr 24, 2024
619e9ae
Removing email route
YashRavipati1 May 22, 2024
91f63ac
hooking email functionality
YashRavipati1 May 22, 2024
0ee3a71
Sending email functionality
YashRavipati1 Apr 24, 2024
f22c124
Demote User
YashRavipati1 May 22, 2024
4b28732
Merge branch 'feature/Yash/EmailSending' of github.com:TritonSE/USHS-…
YashRavipati1 May 22, 2024
c0e3d20
Removing email route
YashRavipati1 May 22, 2024
dc2ce34
Sending email functionality
YashRavipati1 Apr 24, 2024
b19e628
Merge branch 'feature/Yash/EmailSending' of github.com:TritonSE/USHS-…
YashRavipati1 May 23, 2024
9ebabe1
Revert "Demote User"
YashRavipati1 May 23, 2024
c330484
Demote User Email
YashRavipati1 May 23, 2024
7de4a9a
Removing route for email
YashRavipati1 May 23, 2024
4dd63e7
Sending email functionality
YashRavipati1 Apr 24, 2024
481340c
Revert "Sending email functionality"
YashRavipati1 May 23, 2024
60b9dfc
Revert "Resize Images (#96)"
YashRavipati1 May 23, 2024
ea24022
Revert "V2 filters frontend (#90)"
YashRavipati1 May 23, 2024
c539087
Revert "Profile Page: Manage Permissions (#91)"
YashRavipati1 May 23, 2024
1547380
Revert "Renter Candidate Page (#95)"
YashRavipati1 May 23, 2024
7a252ff
demoting user
YashRavipati1 May 23, 2024
59f5989
Cleaning up/removing frontend routes
YashRavipati1 May 23, 2024
d487fea
Fixing referall leased emails
YashRavipati1 May 28, 2024
e828607
assignedHousingLocator instead of renterCandidate
YashRavipati1 May 28, 2024
a05ffa5
build failure
petabite May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified backend/bun.lockb
Binary file not shown.
23 changes: 23 additions & 0 deletions backend/src/controllers/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { RequestHandler } from "express";

import { asyncHandler } from "./wrappers";

import { sendEmail } from "@/services/email";

type SendEmailRequestBody = {
recipient: string;
subject: string;
text: string;
};

export const sendEmailHandler: RequestHandler = asyncHandler(async (req, res, _) => {
const { recipient, subject, text } = req.body as SendEmailRequestBody;

const response = await sendEmail(recipient, subject, text);

if (response !== null) {
res.status(200).json(response);
} else {
res.status(400).send("Email Unsuccessful");
}
});
2 changes: 2 additions & 0 deletions backend/src/routes/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from "express";

import emailRouter from "@/routes/email";
import renterRouter from "@/routes/renter";
import unitsRouter from "@/routes/units";
import userRouter from "@/routes/user";
Expand All @@ -11,5 +12,6 @@ const router = express.Router();
router.use("/users", userRouter);
router.use("/units", unitsRouter);
router.use("/renter-candidates", renterRouter);
router.use("/send-email", emailRouter);

export default router;
9 changes: 9 additions & 0 deletions backend/src/routes/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import express from "express";

import * as EmailController from "@/controllers/email";

const router = express.Router();

router.post("/", EmailController.sendEmailHandler);

export default router;
26 changes: 26 additions & 0 deletions backend/src/services/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import "dotenv/config";

import { createTransport } from "nodemailer";

export async function sendEmail(recipient: string, subjectString: string, body: string) {
const transporter = createTransport({
port: 465, // true for 465, false for other ports
host: "smtp.gmail.com",
auth: {
user: process.env.GMAILUSER,
pass: process.env.GMAILPASS,
},
secure: true,
});

const mailData = {
from: "[email protected]", // sender address
petabite marked this conversation as resolved.
Show resolved Hide resolved
to: recipient, // list of receivers
subject: subjectString,
text: body,
};

const response = await transporter.sendMail(mailData);

return response;
}
17 changes: 17 additions & 0 deletions frontend/src/api/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { APIResult, handleAPIError, post } from "./requests";

export type emailRequest = {
recipient: string;
subject: string;
text: string;
};

export async function sendEmail(email: emailRequest): Promise<APIResult<string>> {
try {
const response = await post("/send-email", email);
const json = (await response.json()) as string;
return { success: true, data: json };
} catch (error) {
return handleAPIError(error);
}
}