From 845261a9b68184710e168cb26f8c83b8df6539bc Mon Sep 17 00:00:00 2001 From: JCantu248 Date: Fri, 22 Dec 2023 15:50:44 -0600 Subject: [PATCH 1/8] Add attachments and templates to email notification. --- backend/src/api/helpers.ts | 40 ++++---------------------------------- backend/src/api/users.ts | 6 +++--- 2 files changed, 7 insertions(+), 39 deletions(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index 004b31da4..61456c29c 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -154,7 +154,7 @@ export const sendUserNotificationEmail = async ( SES: new SES({ region: 'us-east-1' }) }); - /*const client = new S3Client(); + const client = new S3Client(); const html = await client.getEmailAsset(template_file); @@ -164,39 +164,6 @@ export const sendUserNotificationEmail = async ( last_name: p_lastname }; - const htmlToSend = template(data);*/ - - const mailOptions = { - from: process.env.CROSSFEED_SUPPORT_EMAIL_SENDER, - to: recepient, - subject: p_subject, - text: 'Testing' - }; - - await transporter.sendMail(mailOptions); -}; - -export const sendRegionalAdminNotificationEmail = async ( - recepient: string, - p_subject: string, - p_firstName: string, - p_lastname: string, - p_username: string -) => { - const transporter = nodemailer.createTransport({ - SES: new SES({ region: 'us-east-1' }) - }); - - const client = new S3Client(); - const html = await client.getEmailAsset( - 'crossfeed_regional_admin_notification.html' - ); - const template = handlebars.compile(html); - const data = { - first_name: p_firstName, - last_name: p_lastname - }; - const htmlToSend = template(data); const mailOptions = { @@ -204,6 +171,7 @@ export const sendRegionalAdminNotificationEmail = async ( to: recepient, subject: p_subject, html: htmlToSend, + replyTo: process.env.CROSSFEED_SUPPORT_EMAIL_REPLYTO!, attachments: [ { filename: 'banner.png', @@ -232,7 +200,7 @@ export const sendRegionalAdminNotificationEmail = async ( }, { filename: 'facebook.png', - content: await client.getEmailAsset('facebooK.png'), + content: await client.getEmailAsset('facebook.png'), cid: 'CISA Facebook' }, { @@ -244,4 +212,4 @@ export const sendRegionalAdminNotificationEmail = async ( }; await transporter.sendMail(mailOptions); -}; +}; \ No newline at end of file diff --git a/backend/src/api/users.ts b/backend/src/api/users.ts index b610e2cb4..6428a065f 100644 --- a/backend/src/api/users.ts +++ b/backend/src/api/users.ts @@ -610,9 +610,9 @@ export const register = wrapHandler(async (event) => { // ); // Send Basic Text Registration confirmation email to user - await sendRegistrationTextEmail(newUser.email); + // await sendRegistrationTextEmail(newUser.email); // Send Basic HTML Registration confirmation email to user - await sendRegistrationHtmlEmail(newUser.email); + // await sendRegistrationHtmlEmail(newUser.email); // Send new user pending approval email to regionalAdmin // TODO: replace with html email function to regianlAdmin if desired @@ -673,7 +673,7 @@ export const registrationApproval = wrapHandler(async (event) => { } // Send email notification - sendUserNotificationEmail( + await sendUserNotificationEmail( user.email, 'Crossfeed Registration Approved', user.firstName, From 1d8961d2b7766085a289e08058066de8931f3808 Mon Sep 17 00:00:00 2001 From: JCantu248 Date: Fri, 22 Dec 2023 15:57:34 -0600 Subject: [PATCH 2/8] Fix linter errors. --- backend/src/api/helpers.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index 61456c29c..eb0e5a06d 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -156,8 +156,6 @@ export const sendUserNotificationEmail = async ( const client = new S3Client(); const html = await client.getEmailAsset(template_file); - - const template = handlebars.compile(html); const data = { first_name: p_firstName, @@ -212,4 +210,4 @@ export const sendUserNotificationEmail = async ( }; await transporter.sendMail(mailOptions); -}; \ No newline at end of file +}; From 678d33d5e0196a34986a5684700cc754ee9b10ec Mon Sep 17 00:00:00 2001 From: JCantu248 Date: Fri, 22 Dec 2023 16:22:30 -0600 Subject: [PATCH 3/8] Remove docker mapping in template file name. --- backend/src/api/users.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/api/users.ts b/backend/src/api/users.ts index 6428a065f..4a7f9a61f 100644 --- a/backend/src/api/users.ts +++ b/backend/src/api/users.ts @@ -675,10 +675,10 @@ export const registrationApproval = wrapHandler(async (event) => { // Send email notification await sendUserNotificationEmail( user.email, - 'Crossfeed Registration Approved', + 'Crossfeed Registration Pending', user.firstName, user.lastName, - '/app/src/email_templates/crossfeed_approval_notification.html' + 'crossfeed_approval_notification.html' ); // TODO: Handle Response Output From fb4c21dbc430b02a37e43317917dc8b1539cd0f1 Mon Sep 17 00:00:00 2001 From: JCantu248 Date: Fri, 22 Dec 2023 16:25:50 -0600 Subject: [PATCH 4/8] Change crossfeed registration template filename to match S3 bucket. --- backend/src/api/users.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/api/users.ts b/backend/src/api/users.ts index 4a7f9a61f..e6771eabc 100644 --- a/backend/src/api/users.ts +++ b/backend/src/api/users.ts @@ -678,7 +678,7 @@ export const registrationApproval = wrapHandler(async (event) => { 'Crossfeed Registration Pending', user.firstName, user.lastName, - 'crossfeed_approval_notification.html' + 'crossfeed_registration_notification.html' ); // TODO: Handle Response Output From 0e74f5d3beb79b7614c86513bf526ce6633b7cd7 Mon Sep 17 00:00:00 2001 From: JCantu248 Date: Fri, 22 Dec 2023 16:42:42 -0600 Subject: [PATCH 5/8] change first_name, last_name to firstName, lastName. --- backend/src/api/helpers.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index eb0e5a06d..d4052be97 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -158,8 +158,8 @@ export const sendUserNotificationEmail = async ( const html = await client.getEmailAsset(template_file); const template = handlebars.compile(html); const data = { - first_name: p_firstName, - last_name: p_lastname + firstName: p_firstName, + lastName: p_lastname }; const htmlToSend = template(data); @@ -211,3 +211,4 @@ export const sendUserNotificationEmail = async ( await transporter.sendMail(mailOptions); }; + From 27922524e705f6fc41806d67d718a4f22bbd6dda Mon Sep 17 00:00:00 2001 From: JCantu248 Date: Fri, 22 Dec 2023 16:52:30 -0600 Subject: [PATCH 6/8] Change firstname lastname to firstName, lastName. --- .../email_templates/crossfeed_registration_notification.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/email_templates/email_templates/crossfeed_registration_notification.html b/backend/src/email_templates/email_templates/crossfeed_registration_notification.html index 95339c4b4..45231669c 100644 --- a/backend/src/email_templates/email_templates/crossfeed_registration_notification.html +++ b/backend/src/email_templates/email_templates/crossfeed_registration_notification.html @@ -71,7 +71,7 @@

CROSSFEED USER ACCOUNT CREATION

-

{{firstname}} {{lastname}},

+

{{firstName}} {{lastName}},

From db9c726a86758962e7c892ee02ebd1a477d7923b Mon Sep 17 00:00:00 2001 From: nickviola Date: Wed, 27 Dec 2023 09:14:55 -0600 Subject: [PATCH 7/8] Fix casing for user variables in html email templates --- .../email_templates/crossfeed_approval_notification.html | 2 +- .../email_templates/crossfeed_denial_notification.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/email_templates/email_templates/crossfeed_approval_notification.html b/backend/src/email_templates/email_templates/crossfeed_approval_notification.html index 0d9ee4cbb..632ecfad7 100644 --- a/backend/src/email_templates/email_templates/crossfeed_approval_notification.html +++ b/backend/src/email_templates/email_templates/crossfeed_approval_notification.html @@ -64,7 +64,7 @@

CROSSFEED USER ACCOUNT APPROVAL

-

{{firstname}} {{lastname}},

+

{{firstName}} {{lastName}},

diff --git a/backend/src/email_templates/email_templates/crossfeed_denial_notification.html b/backend/src/email_templates/email_templates/crossfeed_denial_notification.html index 8f22d05af..05e7428f4 100644 --- a/backend/src/email_templates/email_templates/crossfeed_denial_notification.html +++ b/backend/src/email_templates/email_templates/crossfeed_denial_notification.html @@ -64,7 +64,7 @@

CROSSFEED USER ACCOUNT APPROVAL

-

{{firstname}} {{lastname}},

+

{{firstName}} {{lastName}},

From 6dab6f85b74a82f19aedec693e4c76dda6ab279b Mon Sep 17 00:00:00 2001 From: nickviola Date: Wed, 27 Dec 2023 17:05:58 -0600 Subject: [PATCH 8/8] Fix linter error in src/api/helpers.ts --- backend/src/api/helpers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index d4052be97..ed12e5132 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -211,4 +211,3 @@ export const sendUserNotificationEmail = async ( await transporter.sendMail(mailOptions); }; -