Skip to content

Commit

Permalink
feat: add a text only fallback to html email and refactor generateEma…
Browse files Browse the repository at this point in the history
…ilHtml()
  • Loading branch information
pmjuu committed Feb 19, 2025
1 parent 2924107 commit d4ed9ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/email-templates/confirm-email.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export function generateEmailHtml(baseUrl: string, token: string) {
const activationUrl = `${baseUrl}/auth/activate?token=${token}`;
const logoUrl = `${baseUrl}/assets/torontojs-logo.png`;

export function generateEmailHtml(activationUrl: string, logoUrl: string) {
return `
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
Expand Down
6 changes: 5 additions & 1 deletion src/routes/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ authRoutes.post('/sign-up', async (context: Context<EnvironmentBindings>) => {
{ expirationTtl: 60 * 10 }
);

const emailHtmlTemplate = generateEmailHtml(context.env.BASE_URL, encodedToken);
const activationUrl = `${context.env.BASE_URL}/auth/activate?token=${encodedToken}`;
const logoUrl = `${context.env.BASE_URL}/assets/torontojs-logo.png`;
const emailText = `Please confirm your account by clicking the following link: ${activationUrl}`;
const emailHtmlTemplate = generateEmailHtml(activationUrl, logoUrl);
const msg = {
to: parsedBody.email,
from: context.env.SENDER_EMAIL,
subject: '[TorontoJS] Confirm your account',
text: emailText,
html: emailHtmlTemplate
};
await sgMail.send(msg);
Expand Down

0 comments on commit d4ed9ce

Please sign in to comment.