diff --git a/packages/connectors/connector-mailgun/src/index.test.ts b/packages/connectors/connector-mailgun/src/index.test.ts index 19773289d..b01898200 100644 --- a/packages/connectors/connector-mailgun/src/index.test.ts +++ b/packages/connectors/connector-mailgun/src/index.test.ts @@ -258,13 +258,13 @@ describe('Maligun connector', () => { to: 'bar@example.com', subject: 'Passcode 123456', html: '

Your passcode is 123456

', - 'h:Reply-To': 'Reply to bar@example.com', + 'h:Reply-To': 'Reply to foo@email.com', }); getI18nEmailTemplate.mockResolvedValue({ subject: 'Passcode {{code}}', content: '

Your passcode is {{code}}

', - replyTo: 'Reply to {{to}}', + replyTo: 'Reply to {{user.primaryEmail}}', } satisfies EmailTemplateDetails); getConfig.mockResolvedValue({ @@ -281,7 +281,7 @@ describe('Maligun connector', () => { await connector.sendMessage({ to: 'bar@example.com', type: TemplateType.Generic, - payload: { code: '123456' }, + payload: { code: '123456', user: { primaryEmail: 'foo@email.com' } }, }); }); @@ -292,15 +292,15 @@ describe('Maligun connector', () => { subject: 'Passcode 123456', html: 'Your passcode is 123456', text: 'Your passcode is 123456', - 'h:Reply-To': 'Reply to bar@example.com', + 'h:Reply-To': 'Reply to {{user.primaryEmail}}', }); getI18nEmailTemplate.mockResolvedValue({ subject: 'Passcode {{code}}', content: 'Your passcode is {{code}}', - replyTo: 'Reply to {{to}}', + replyTo: 'Reply to {{user.primaryEmail}}', contentType: 'text/plain', - sendFrom: `{{applicationName}} <${baseConfig.from}>`, + sendFrom: `{{application.name}} <${baseConfig.from}>`, } satisfies EmailTemplateDetails); getConfig.mockResolvedValue({ @@ -309,7 +309,7 @@ describe('Maligun connector', () => { [TemplateType.Generic]: { subject: 'Verification code is {{code}}', html: '

Your verification code is {{code}}

', - replyTo: 'baz@example.com', + replyTo: 'no-reply@mail.com', }, }, }); @@ -317,7 +317,7 @@ describe('Maligun connector', () => { await connector.sendMessage({ to: 'bar@example.com', type: TemplateType.Generic, - payload: { code: '123456', applicationName: 'Foo' }, + payload: { code: '123456', application: { name: 'Foo' } }, }); }); }); diff --git a/packages/connectors/connector-mailgun/src/index.ts b/packages/connectors/connector-mailgun/src/index.ts index 0b7d4e0bf..1ddf20dea 100644 --- a/packages/connectors/connector-mailgun/src/index.ts +++ b/packages/connectors/connector-mailgun/src/index.ts @@ -81,10 +81,7 @@ const sendMessage = ( const template = deliveries[type] ?? deliveries[TemplateType.Generic]; const data = customTemplate - ? getDataFromCustomTemplate(customTemplate, { - ...payload, - to, - }) + ? getDataFromCustomTemplate(customTemplate, payload) : // Fallback to the default template if the custom i18n template is not found. template && getDataFromDeliveryConfig(template, payload); diff --git a/packages/connectors/connector-sendgrid-email/src/index.test.ts b/packages/connectors/connector-sendgrid-email/src/index.test.ts index 7aae05b8e..c00a844af 100644 --- a/packages/connectors/connector-sendgrid-email/src/index.test.ts +++ b/packages/connectors/connector-sendgrid-email/src/index.test.ts @@ -89,12 +89,11 @@ describe('SendGrid connector', () => { subject: 'Passcode {{code}}', content: '

Your passcode is {{code}}

', contentType: 'text/html', - sendFrom: '{{applicationName}}', - replyTo: '{{userName}}', + sendFrom: '{{application.name}}', }); nockMessages({ - personalizations: [{ to: [{ email: toEmail, name: 'John Doe' }] }], + personalizations: [{ to: [{ email: toEmail }] }], from: { email: fromEmail, name: 'Test app' }, subject: 'Passcode 123456', content: [ @@ -112,8 +111,7 @@ describe('SendGrid connector', () => { type: TemplateType.Generic, payload: { code: '123456', - applicationName: 'Test app', - userName: 'John Doe', + application: { name: 'Test app' }, }, }); }); diff --git a/packages/connectors/connector-sendgrid-email/src/index.ts b/packages/connectors/connector-sendgrid-email/src/index.ts index dcfed9ba7..245c0d483 100644 --- a/packages/connectors/connector-sendgrid-email/src/index.ts +++ b/packages/connectors/connector-sendgrid-email/src/index.ts @@ -47,7 +47,7 @@ const buildParametersFromDefaultTemplate = ( const buildParametersFromCustomTemplate = ( to: string, config: SendGridMailConfig, - { subject, content, replyTo, sendFrom, contentType = 'text/html' }: EmailTemplateDetails, + { subject, content, sendFrom, contentType = 'text/html' }: EmailTemplateDetails, payload: SendMessagePayload ): PublicParameters => { return { @@ -56,8 +56,7 @@ const buildParametersFromCustomTemplate = ( to: [ { email: to, - // If replyTo is provided, we will replace the handlebars with the payload - ...conditional(replyTo && { name: replaceSendMessageHandlebars(replyTo, payload) }), + ...conditional(config.fromName && { name: config.fromName }), }, ], }, diff --git a/packages/connectors/connector-smtp/src/index.test.ts b/packages/connectors/connector-smtp/src/index.test.ts index b490c1b47..382c82513 100644 --- a/packages/connectors/connector-smtp/src/index.test.ts +++ b/packages/connectors/connector-smtp/src/index.test.ts @@ -167,8 +167,8 @@ describe('Test SMTP connector with custom i18n templates', () => { subject: 'Custom subject {{code}}', content: 'Your verification code is {{code}}', contentType: 'text/plain', - replyTo: `{{userName}}`, - sendFrom: `{{applicationName}} `, + replyTo: `{{user.primaryEmail}}`, + sendFrom: `{{application.name}} `, } satisfies EmailTemplateDetails); const connector = await createConnector({ getConfig, getI18nEmailTemplate }); @@ -176,7 +176,11 @@ describe('Test SMTP connector with custom i18n templates', () => { await connector.sendMessage({ to: 'bar', type: TemplateType.SignIn, - payload: { code: '234567', userName: 'John Doe', applicationName: 'Test app' }, + payload: { + code: '234567', + user: { primaryEmail: 'test@email.com' }, + application: { name: 'Test app' }, + }, }); expect(sendMail).toHaveBeenCalledWith({ @@ -184,7 +188,7 @@ describe('Test SMTP connector with custom i18n templates', () => { subject: 'Custom subject 234567', text: 'Your verification code is 234567', to: 'bar', - replyTo: 'John Doe', + replyTo: 'test@email.com', }); }); }); diff --git a/packages/toolkit/connector-kit/src/types/email-template.ts b/packages/toolkit/connector-kit/src/types/email-template.ts index cec271b64..0294c6fcc 100644 --- a/packages/toolkit/connector-kit/src/types/email-template.ts +++ b/packages/toolkit/connector-kit/src/types/email-template.ts @@ -14,16 +14,12 @@ export type EmailTemplateDetails = { * OPTIONAL: Custom replyTo template. * * Based on the email client, the replyTo field may be used to customize the reply-to field of the email. - * @remarks - * The original reply email value can be found in the template variables. */ replyTo?: string; /** * OPTIONAL: Custom from template. * * Based on the email client, the sendFrom field may be used to customize the from field of the email. - * @remarks - * The sender email value can be found in the template variables. */ sendFrom?: string; };