Skip to content

Commit

Permalink
Feature/daniel vsr email (#14)
Browse files Browse the repository at this point in the history
Notification email to staff upon VSR submission
  • Loading branch information
holychickencow authored Feb 14, 2024
1 parent af2e281 commit 70c48b6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions backend/src/services/emails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import "dotenv/config";
import nodemailer from "nodemailer";
import env from "../util/validateEnv";

/**
* Sends a notification email to PAP staff when a VSR is submitted.
* Throws an error if the email could not be sent.
*
* @param name Name of veteran who submitted the VSR
* @param email Email address of veteran who submitted the VSR
*/
const sendVSRNotificationEmailToStaff = async (name: string, email: string) => {
const EMAIL_SUBJECT = "New VSR Submitted";
const EMAIL_BODY = `A new VSR was submitted by ${name} from ${email}`;

const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: env.EMAIL_USER,
pass: env.EMAIL_APP_PASSWORD,
},
});

const mailOptions = {
from: env.EMAIL_USER,
to: env.EMAIL_NOTIFICATIONS_RECIPIENT,
subject: EMAIL_SUBJECT,
text: EMAIL_BODY,
};

await transporter.sendMail(mailOptions);
};

export { sendVSRNotificationEmailToStaff };
1 change: 1 addition & 0 deletions backend/src/util/validateEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export default cleanEnv(process.env, {
FRONTEND_ORIGIN: str(), // URL of frontend, to allow CORS from frontend
EMAIL_USER: email(), // Email address to use for sending emails
EMAIL_APP_PASSWORD: str(), // App password to use for sending emails
EMAIL_NOTIFICATIONS_RECIPIENT: email(), // Recipient of VSR notification emails
BACKEND_FIREBASE_SETTINGS: json(), // Firebase settings for backend, stored as a JSON string
});

0 comments on commit 70c48b6

Please sign in to comment.