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

Feature/daniel vsr email #14

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
});
Loading