@@ -3,11 +3,20 @@ import { render } from "@react-email/render";
33import { writeFileSync , mkdirSync } from "fs" ;
44import { join } from "path" ;
55import { exec } from "child_process" ;
6- import CreateAccountInvite , { CreateAccountInviteProps } from "./templates/CreateAccountInvite" ;
7- import ItemsVisibleNotification , { ItemsVisibleNotificationProps } from "./templates/ItemsVisibleNotification" ;
8- import DonorOfferCreated , { DonorOfferCreatedProps } from "./templates/DonorOfferCreated" ;
9- import CreateAccountReminder , { CreateAccountReminderProps } from "./templates/CreateAccountReminder" ;
6+ import CreateAccountInvite , {
7+ CreateAccountInviteProps ,
8+ } from "./templates/CreateAccountInvite" ;
9+ import ItemsVisibleNotification , {
10+ ItemsVisibleNotificationProps ,
11+ } from "./templates/ItemsVisibleNotification" ;
12+ import DonorOfferCreated , {
13+ DonorOfferCreatedProps ,
14+ } from "./templates/DonorOfferCreated" ;
15+ import CreateAccountReminder , {
16+ CreateAccountReminderProps ,
17+ } from "./templates/CreateAccountReminder" ;
1018import ExpiringItems , { ExpiringItemsProps } from "./templates/ExpiringItems" ;
19+ import ResetPassword , { ResetPasswordProps } from "./templates/ResetPassword" ;
1120
1221const apiKey = process . env . SENDGRID_API_KEY as string ;
1322const fromEmail = process . env . SENDGRID_SENDER as string ;
@@ -43,50 +52,50 @@ export async function sendEmail(
4352 html : string
4453) : Promise < [ SendGrid . ClientResponse , object ] | void > {
4554 if ( openLocally ) {
46- const timestamp = new Date ( ) . toISOString ( ) . replace ( / [: .] / g, '-' ) ;
55+ const timestamp = new Date ( ) . toISOString ( ) . replace ( / [: .] / g, "-" ) ;
4756 const filename = `email-preview-${ timestamp } .html` ;
48- const previewsDir = join ( process . cwd ( ) , ' email-previews' ) ;
57+ const previewsDir = join ( process . cwd ( ) , " email-previews" ) ;
4958 const filepath = join ( previewsDir , filename ) ;
50-
59+
5160 try {
5261 writeFileSync ( filepath , html ) ;
5362 } catch {
5463 mkdirSync ( previewsDir , { recursive : true } ) ;
5564 writeFileSync ( filepath , html ) ;
5665 }
57-
58- const relativePath = `email-previews/${ filename } ` ;
59- console . log ( `📧 Email preview saved: ${ relativePath } ` ) ;
60-
61- const fileUrl = `file://${ filepath } ` ;
62- const platform = process . platform ;
63-
66+
67+ const relativePath = `email-previews/${ filename } ` ;
68+ console . log ( `📧 Email preview saved: ${ relativePath } ` ) ;
69+
70+ const fileUrl = `file://${ filepath } ` ;
71+ const platform = process . platform ;
72+
6473 let command : string ;
65- if ( platform === ' darwin' ) {
74+ if ( platform === " darwin" ) {
6675 command = `open -n "${ fileUrl } "` ;
67- } else if ( platform === ' win32' ) {
76+ } else if ( platform === " win32" ) {
6877 command = `start "" "${ fileUrl } "` ;
6978 } else {
7079 command = `xdg-open "${ fileUrl } "` ;
7180 }
72-
81+
7382 exec ( command , ( error ) => {
7483 if ( error ) {
75- console . log ( `📧 Could not auto-open browser. Please open manually: ${ fileUrl } ` ) ;
84+ console . log (
85+ `📧 Could not auto-open browser. Please open manually: ${ fileUrl } `
86+ ) ;
7687 } else {
7788 console . log ( `📧 Email preview opened in browser` ) ;
7889 }
7990 } ) ;
80-
91+
8192 return ;
8293 }
8394
84- return SendGrid . send ( {
85- to,
86- from : fromEmail ,
87- subject,
88- html,
89- } , Array . isArray ( to ) ) ;
95+ return SendGrid . send (
96+ { to, from : fromEmail , subject, html } ,
97+ Array . isArray ( to )
98+ ) ;
9099}
91100
92101export class EmailClient {
@@ -95,15 +104,15 @@ export class EmailClient {
95104 return sendEmail ( to , "Your Invite Link" , html ) ;
96105 }
97106
98- static async sendUserInviteReminder ( to : string , props : CreateAccountReminderProps ) {
107+ static async sendUserInviteReminder (
108+ to : string ,
109+ props : CreateAccountReminderProps
110+ ) {
99111 const html = await render ( CreateAccountReminder ( props ) ) ;
100112 return sendEmail ( to , "Reminder: Complete Your Account" , html ) ;
101113 }
102114
103- static async sendItemsExpiring (
104- to : string ,
105- props : ExpiringItemsProps
106- ) {
115+ static async sendItemsExpiring ( to : string , props : ExpiringItemsProps ) {
107116 const html = await render ( ExpiringItems ( props ) ) ;
108117 return sendEmail ( to , `Items Expiring in ${ props . month } ` , html ) ;
109118 }
@@ -123,4 +132,9 @@ export class EmailClient {
123132 const html = await render ( DonorOfferCreated ( props ) ) ;
124133 return sendEmail ( to , "Donor Offer Created" , html ) ;
125134 }
135+
136+ static async sendPasswordReset ( to : string , props : ResetPasswordProps ) {
137+ const html = await render ( ResetPassword ( props ) ) ;
138+ return sendEmail ( to , "Reset Your Password" , html ) ;
139+ }
126140}
0 commit comments