Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(workflows): send html-only emails without a text part (#105632)

Daniel Marchuk250f9d2e32b7
diff --git a/nodejs/src/cdp/schema/cyclotron.ts b/nodejs/src/cdp/schema/cyclotron.ts
index b2df321e8fee..a592478213a5 100644
--- a/nodejs/src/cdp/schema/cyclotron.ts
+++ b/nodejs/src/cdp/schema/cyclotron.ts
@@ -164,7 +164,8 @@ export const CyclotronInvocationQueueParametersEmailSchema = z.object({
bcc: z.string().optional(),
subject: z.string(),
preheader: z.string().optional(),
- text: z.string(),
+ // Emails authored through the API or MCP often carry html only.
+ text: z.string().optional(),
html: z.string(),
})
diff --git a/nodejs/src/cdp/services/messaging/email.service.test.ts b/nodejs/src/cdp/services/messaging/email.service.test.ts
index b1feda043a43..92ff4898c393 100644
--- a/nodejs/src/cdp/services/messaging/email.service.test.ts
+++ b/nodejs/src/cdp/services/messaging/email.service.test.ts
@@ -3,7 +3,10 @@ import { mockFetch } from '~/tests/helpers/mocks/request.mock'
import { MessageRejected, SendingPausedException, TooManyRequestsException } from '@aws-sdk/client-sesv2'
import { createExampleInvocation, insertIntegration } from '~/cdp/_tests/fixtures'
-import { CyclotronInvocationQueueParametersEmailType } from '~/cdp/schema/cyclotron'
+import {
+ CyclotronInvocationQueueParametersEmailSchema,
+ CyclotronInvocationQueueParametersEmailType,
+} from '~/cdp/schema/cyclotron'
import { CyclotronJobInvocationHogFunction } from '~/cdp/types'
import { createRedisV2PoolFromConfig } from '~/common/redis/redis-v2'
import { closeHub, createHub } from '~/common/utils/db/hub'
@@ -1350,22 +1353,23 @@ describe('EmailService', () => {
])
})
- it('should send plaintext-only email when html is empty', async () => {
+ it.each([
+ ['text only', { html: '', text: 'Hello, this is a plain text email.' }, ['Text']],
+ ['html only, no text', { html: '<p>Hello</p>', text: undefined }, ['Html']],
+ ['html only, empty text', { html: '<p>Hello</p>', text: '' }, ['Html']],
+ ])('sends only the parts that have content: %s', async (_name, content, expectedParts) => {
sendEmailSpy.mockResolvedValue({ MessageId: 'test-message-id' })
invocation.hogFunction.metadata = { message_category_type: 'transactional' }
- invocation.queueParameters = createEmailParams({
- from: { integrationId: 1 },
- html: '',
- text: 'Hello, this is a plain text email.',
- })
+ invocation.queueParameters = CyclotronInvocationQueueParametersEmailSchema.parse(
+ createEmailParams({ from: { integrationId: 1 }, ...content })
+ )
const result = await service.executeSendEmail(invocation)
expect(result.error).toBeUndefined()
const sentCommand = sendEmailSpy.mock.calls[0][0] as { input: any }
- expect(sentCommand.input.Content.Simple.Body.Text).toEqual({
- Data: 'Hello, this is a plain text email.',
- Charset: 'UTF-8',
- })
- expect(sentCommand.input.Content.Simple.Body.Html).toBeUndefined()
+ expect(Object.keys(sentCommand.input.Content.Simple.Body)).toEqual(expectedParts)
+ if (content.text) {
+ expect(sentCommand.input.Content.Simple.Body.Text).toEqual({ Data: content.text, Charset: 'UTF-8' })
+ }
})
it('should not include preheader span if not in params', async () => {
diff --git a/nodejs/src/cdp/services/messaging/email.service.ts b/nodejs/src/cdp/services/messaging/email.service.ts
index d786ceff9f04..1348f74e4917 100644
--- a/nodejs/src/cdp/services/messaging/email.service.ts
+++ b/nodejs/src/cdp/services/messaging/email.service.ts
@@ -977,7 +977,7 @@ export class EmailService {
from: from.name ? `"${from.name}" <${from.email}>` : from.email,
to: params.to.name ? `"${params.to.name}" <${params.to.email}>` : params.to.email,
subject: sanitizeEmailSubject(params.subject),
- text: params.text,
+ ...(params.text ? { text: params.text } : {}),
headers: { [AUTO_SUBMITTED_HEADER.Name!]: AUTO_SUBMITTED_HEADER.Value! },
...(params.html
? {
@@ -1060,10 +1060,7 @@ export class EmailService {
Charset: 'UTF-8',
},
Body: {
- Text: {
- Data: params.text,
- Charset: 'UTF-8',
- },
+ ...(params.text ? { Text: { Data: params.text, Charset: 'UTF-8' } } : {}),
...htmlBody,
},
},