diff --git a/server/scripts/email/send-test-email.ts b/server/scripts/email/send-test-email.ts index 7c53ee22b..0c3b8a8e5 100644 --- a/server/scripts/email/send-test-email.ts +++ b/server/scripts/email/send-test-email.ts @@ -21,7 +21,8 @@ if (require.main === module) { await SendEmail( options.email, "Hello World", - MainHTMLWrapper("Hello world! This is a test email for doing things.") + MainHTMLWrapper("Hello world! This is a test email for doing things."), + "Hello world! This is a test email for doing things." ); logger.info(`Done.`); process.exit(0); diff --git a/server/src/lib/email/client.ts b/server/src/lib/email/client.ts index fb38c777b..38da40a62 100644 --- a/server/src/lib/email/client.ts +++ b/server/src/lib/email/client.ts @@ -45,7 +45,8 @@ if (ServerConfig.EMAIL_CONFIG) { export function SendEmail( to: string, subject: string, - htmlContent: string + htmlContent: string, + textContent: string ): Promise | undefined { if (Environment.nodeEnv === "test") { logger.debug(`Stubbed out SendEmail as env was test.`); @@ -64,6 +65,7 @@ export function SendEmail( to, subject, html: htmlContent, + text: textContent, dkim: ServerConfig.EMAIL_CONFIG?.DKIM, }); } diff --git a/server/src/lib/email/formats.ts b/server/src/lib/email/formats.ts index e25c3806f..94a7a106c 100644 --- a/server/src/lib/email/formats.ts +++ b/server/src/lib/email/formats.ts @@ -4,15 +4,24 @@ import { ServerConfig, TachiConfig } from "lib/setup/config"; export function EmailFormatResetPassword(username: string, resetCode: string, ipAddr: string) { - return MainHTMLWrapper( - `Hey ${username}, you've recieved a password reset request.
Click here to perform the reset.
If you did not request this reset, report this! This reset request was made by ${ipAddr}.` - ); + return { + html: MainHTMLWrapper( + `Hey ${username}, you've recieved a password reset request.
Click here to perform the reset.
If you did not request this reset, report this! This reset request was made by ${ipAddr}.` + ), + text: `Hey ${username}, you've recieved a password reset request. This link +${ServerConfig.OUR_URL}/reset-password?code=${resetCode} will perform the reset. +If you did not request this reset, report this! This reset request was made by ${ipAddr}.`, + }; } export function EmailFormatVerifyEmail(username: string, code: string) { - return MainHTMLWrapper( - `Hey ${username}, You need to verify your email before you can use the site.
Click here to verify your email.` - ); + return { + html: MainHTMLWrapper( + `Hey ${username}, You need to verify your email before you can use the site.
Click here to verify your email.` + ), + text: `Hey ${username}, You need to verify your email before you can use the site. +Please go to ${ServerConfig.OUR_URL}/verify-email?code=${code} to verify!`, + }; } export function MainHTMLWrapper(innerHTML: string) { diff --git a/server/src/server/router/api/v1/auth/router.ts b/server/src/server/router/api/v1/auth/router.ts index bf69b38e8..b1a6ad2b1 100644 --- a/server/src/server/router/api/v1/auth/router.ts +++ b/server/src/server/router/api/v1/auth/router.ts @@ -280,11 +280,9 @@ router.post( email: req.body.email, }); - SendEmail( - req.body.email, - "Email Verification", - EmailFormatVerifyEmail(user!.username, resetEmailCode) - ); + const { text, html } = EmailFormatVerifyEmail(user!.username, resetEmailCode); + + SendEmail(req.body.email, "Email Verification", html, text); return res.status(200).json({ success: true, @@ -387,11 +385,10 @@ router.post("/resend-verify-email", prValidate({ email: "string" }), async (req, } // Send the email again. - SendEmail( - req.body.email, - "Email Verification", - EmailFormatVerifyEmail(user!.username, verifyInfo.code) - ); + + const { text, html } = EmailFormatVerifyEmail(user!.username, verifyInfo.code); + + SendEmail(req.body.email, "Email Verification", html, text); }); /** @@ -461,11 +458,9 @@ router.post("/forgot-password", prValidate({ email: "string" }), async (req, res createdOn: Date.now(), }); - SendEmail( - userPrivateInfo.email, - "Reset Password", - EmailFormatResetPassword(user.username, code, req.ip) - ); + const { html, text } = EmailFormatResetPassword(user.username, code, req.ip); + + SendEmail(userPrivateInfo.email, "Reset Password", html, text); } else { logger.info( `Silently rejected password reset request for ${req.body.email}, as no user has this email.`