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

Add attachments and templates to email notification. #2432

Merged
40 changes: 3 additions & 37 deletions backend/src/api/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,43 +154,8 @@ export const sendUserNotificationEmail = async (
SES: new SES({ region: 'us-east-1' })
});

/*const client = new S3Client();
const html = await client.getEmailAsset(template_file);


const template = handlebars.compile(html);
const data = {
first_name: p_firstName,
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 html = await client.getEmailAsset(template_file);
const template = handlebars.compile(html);
const data = {
first_name: p_firstName,
Expand All @@ -204,6 +169,7 @@ export const sendRegionalAdminNotificationEmail = async (
to: recepient,
subject: p_subject,
html: htmlToSend,
replyTo: process.env.CROSSFEED_SUPPORT_EMAIL_REPLYTO!,
attachments: [
{
filename: 'banner.png',
Expand Down Expand Up @@ -232,7 +198,7 @@ export const sendRegionalAdminNotificationEmail = async (
},
{
filename: 'facebook.png',
content: await client.getEmailAsset('facebooK.png'),
content: await client.getEmailAsset('facebook.png'),
cid: 'CISA Facebook'
},
{
Expand Down
10 changes: 5 additions & 5 deletions backend/src/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -673,12 +673,12 @@ export const registrationApproval = wrapHandler(async (event) => {
}

// Send email notification
sendUserNotificationEmail(
await sendUserNotificationEmail(
user.email,
'Crossfeed Registration Approved',
'Crossfeed Registration Pending',
user.firstName,
user.lastName,
'/app/src/email_templates/crossfeed_approval_notification.html'
'crossfeed_registration_notification.html'
);

// TODO: Handle Response Output
Expand Down
Loading