From da8d1c46ac2aed997bb31542afa7d8756bb8a464 Mon Sep 17 00:00:00 2001 From: Baptiste Studer Date: Fri, 24 Mar 2023 12:53:54 +0100 Subject: [PATCH 1/2] fix(login-magic-link): Display auth url in body --- packages/emails/login-magic-link.mjml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/emails/login-magic-link.mjml b/packages/emails/login-magic-link.mjml index 4e5605b0..d588de7d 100644 --- a/packages/emails/login-magic-link.mjml +++ b/packages/emails/login-magic-link.mjml @@ -14,7 +14,8 @@ Me Connecter -

Le bouton ne s'affiche pas ? Cliquez ici

+

Le bouton ne fonctionne pas ?
Copiez/collez cette url dans votre navigateur pour vous connecter :

+

{{url}}

From 3f52ef36b6ab6fc359ea40690832dcf1f751b7f3 Mon Sep 17 00:00:00 2001 From: Baptiste Studer Date: Fri, 24 Mar 2023 12:55:35 +0100 Subject: [PATCH 2/2] fix(mails): Deactivate link tracking for login --- .../modules/notifications/services/mails.ts | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/server/src/modules/notifications/services/mails.ts b/packages/server/src/modules/notifications/services/mails.ts index 94bbb69e..40e7739b 100644 --- a/packages/server/src/modules/notifications/services/mails.ts +++ b/packages/server/src/modules/notifications/services/mails.ts @@ -1,4 +1,4 @@ -import mailClient from "@sendgrid/mail"; +import mailClient, { MailDataRequired } from "@sendgrid/mail"; import invariant from "tiny-invariant"; import { logger } from "../../../logger"; @@ -22,11 +22,23 @@ interface TemplateData { }; } +interface TemplateConfig { + templateId: string; + asmGroupId?: number; + trackingSettings?: MailDataRequired["trackingSettings"]; +} + const TEMPLATE_NAME_TO_CONFIG: { - [k in TemplateName]: { templateId: string; asmGroupId?: number }; + [k in TemplateName]: TemplateConfig; } = { "login-magic-link": { templateId: "d-a64abce41def4af0915688059ed632ac", + trackingSettings: { + clickTracking: { + enable: false, + enableText: false, + }, + }, }, }; @@ -37,30 +49,27 @@ export async function sendMail( templateName: T, templateData: TemplateData[T] ) { - const config = TEMPLATE_NAME_TO_CONFIG[templateName]; + const templateConfig = TEMPLATE_NAME_TO_CONFIG[templateName]; - if (!config) { + if (!templateConfig) { throw new Error(`Could not find config for email ${templateName}`); } await doSendEmail({ to, + templateConfig, templateData, - templateId: config.templateId, - asmGroupId: config.asmGroupId, }); } async function doSendEmail({ to, - templateId, + templateConfig, templateData, - asmGroupId, }: { to: string; - templateId: string; + templateConfig: TemplateConfig; templateData: TemplateData[TemplateName]; - asmGroupId?: number; }) { try { await mailClient.send({ @@ -68,11 +77,11 @@ async function doSendEmail({ email: MAIL_SENDER, name: MAIL_NAME, }, - templateId, - ...(asmGroupId + templateId: templateConfig.templateId, + ...(templateConfig.asmGroupId ? { asm: { - groupId: asmGroupId, + groupId: templateConfig.asmGroupId, }, } : {}), @@ -86,6 +95,7 @@ async function doSendEmail({ dynamicTemplateData: templateData as any, }, ], + ...(templateConfig.trackingSettings || {}), }); } catch (err) { logger.error(err);