Skip to content

The open alternative to Salesforce, designed for AI.

test(server): cover workflow email and calendar actions across providers (#24181)

neo773f0cf70ea5018
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util.ts
new file mode 100644
index 00000000000..169bb05e23a
--- /dev/null
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util.ts
@@ -0,0 +1,232 @@
+import gql from 'graphql-tag';
+import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';
+import { isDefined } from 'twenty-shared/utils';
+import {
+ destroyWorkflowRun,
+ runWorkflowVersion,
+ waitForWorkflowCompletion,
+ type WorkflowRunStatusType,
+} from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';
+import { makeGraphqlAPIRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';
+
+type WorkflowActionStepType =
+ | 'SEND_EMAIL'
+ | 'DRAFT_EMAIL'
+ | 'CREATE_CALENDAR_EVENT';
+
+type WorkflowVersionStep = {
+ id: string;
+ type: string;
+ settings: { input: Record<string, unknown> };
+};
+
+export type WorkflowActionStepRun = {
+ status?: WorkflowRunStatusType;
+ stepStatus?: string;
+ stepResult?: Record<string, unknown>;
+};
+
+const createWorkflow = async (name: string): Promise<string> => {
+ const response = await makeGraphqlAPIRequest({
+ query: gql`
+ mutation CreateWorkflow($name: String!) {
+ createWorkflow(data: { name: $name }) {
+ id
+ }
+ }
+ `,
+ variables: { name },
+ });
+
+ expect(response.body.errors).toBeUndefined();
+
+ return response.body.data.createWorkflow.id;
+};
+
+const destroyWorkflow = async (workflowId: string): Promise<void> => {
+ await makeGraphqlAPIRequest({
+ query: gql`
+ mutation DestroyWorkflow($id: ID!) {
+ destroyWorkflow(id: $id) {
+ id
+ }
+ }
+ `,
+ variables: { id: workflowId },
+ });
+};
+
+const findDraftWorkflowVersionId = async (
+ workflowId: string,
+): Promise<string> => {
+ const response = await makeGraphqlAPIRequest({
+ query: gql`
+ query FindDraftWorkflowVersion($workflowId: UUID!) {
+ workflowVersions(
+ filter: { workflowId: { eq: $workflowId }, status: { in: ["DRAFT"] } }
+ ) {
+ edges {
+ node {
+ id
+ }
+ }
+ }
+ }
+ `,
+ variables: { workflowId },
+ });
+
+ expect(response.body.errors).toBeUndefined();
+
+ return response.body.data.workflowVersions.edges[0].node.id;
+};
+
+const createWorkflowVersionStep = async ({
+ workflowVersionId,
+ stepType,
+}: {
+ workflowVersionId: string;
+ stepType: WorkflowActionStepType;
+}): Promise<void> => {
+ const response = await makeGraphqlAPIRequest({
+ query: gql`
+ mutation CreateWorkflowVersionStep(
+ $input: CreateWorkflowVersionStepInput!
+ ) {
+ createWorkflowVersionStep(input: $input) {
+ stepsDiff
+ }
+ }
+ `,
+ variables: {
+ input: {
+ workflowVersionId,
+ stepType,
+ parentStepId: 'trigger',
+ position: { x: 200, y: 0 },
+ },
+ },
+ });
+
+ expect(response.body.errors).toBeUndefined();
+};
+
+const findWorkflowVersionStep = async ({
+ workflowVersionId,
+ stepType,
+}: {
+ workflowVersionId: string;
+ stepType: WorkflowActionStepType;
+}): Promise<WorkflowVersionStep> => {
+ const response = await makeGraphqlAPIRequest({
+ query: gql`
+ query FindWorkflowVersionSteps($workflowVersionId: UUID!) {
+ workflowVersion(filter: { id: { eq: $workflowVersionId } }) {
+ steps
+ }
+ }
+ `,
+ variables: { workflowVersionId },
+ });
+
+ expect(response.body.errors).toBeUndefined();
+
+ const step = response.body.data.workflowVersion.steps.find(
+ (workflowVersionStep: WorkflowVersionStep) =>
+ workflowVersionStep.type === stepType,
+ );
+
+ expect(step).toBeDefined();
+
+ return step;
+};
+
+const updateWorkflowVersionStepInput = async ({
+ workflowVersionId,
+ step,
+ input,
+}: {
+ workflowVersionId: string;
+ step: WorkflowVersionStep;
+ input: Record<string, unknown>;
+}): Promise<void> => {
+ const response = await makeGraphqlAPIRequest({
+ query: gql`
+ mutation UpdateWorkflowVersionStep(
+ $input: UpdateWorkflowVersionStepInput!
+ ) {
+ updateWorkflowVersionStep(input: $input) {
+ id
+ }
+ }
+ `,
+ variables: {
+ input: {
+ workflowVersionId,
+ step: {
+ ...step,
+ settings: {
+ ...step.settings,
+ input: { ...step.settings.input, ...input },
+ },
+ },
+ },
+ },
+ });
+
+ expect(response.body.errors).toBeUndefined();
+};
+
+export const runWorkflowActionStep = async ({
+ name,
+ stepType,
+ input,
+ payload,
+}: {
+ name: string;
+ stepType: WorkflowActionStepType;
+ input: Record<string, unknown>;
+ payload?: object;
+}): Promise<WorkflowActionStepRun> => {
+ const workflowId = await createWorkflow(name);
+
+ let workflowRunId: string | undefined;
+
+ try {
+ const workflowVersionId = await findDraftWorkflowVersionId(workflowId);
+
+ await updateWorkflowVersionTrigger({
+ workflowVersionId,
+ trigger: {
+ name: 'Manual Trigger',
+ type: 'MANUAL',
+ settings: { outputSchema: {} },
+ nextStepIds: [],
+ position: { x: 0, y: 0 },
+ },
+ });
+
+ await createWorkflowVersionStep({ workflowVersionId, stepType });
+
+ const step = await findWorkflowVersionStep({ workflowVersionId, stepType });
+
+ await updateWorkflowVersionStepInput({ workflowVersionId, step, input });
+
+ workflowRunId = await runWorkflowVersion({ workflowVersionId, payload });
+
+ const workflowRun = await waitForWorkflowCompletion(workflowRunId);
+ const stepInfo = workflowRun?.state?.stepInfos?.[step.id];
+
+ return {
+ status: workflowRun?.status,
+ stepStatus: stepInfo?.status,
+ stepResult: stepInfo?.result,
+ };
+ } finally {
+ if (isDefined(workflowRunId)) {
+ await destroyWorkflowRun(workflowRunId);
+ }
+
+ await destroyWorkflow(workflowId);
+ }
+};
diff --git a/packages/twenty-server/test/integration/workflow-actions/create-calendar-event/drivers/caldav.integration-spec.ts b/packages/twenty-server/test/integration/workflow-actions/create-calendar-event/drivers/caldav.integration-spec.ts
new file mode 100644
index 00000000000..e362f0cfefd
--- /dev/null
+++ b/packages/twenty-server/test/integration/workflow-actions/create-calendar-event/drivers/caldav.integration-spec.ts
@@ -0,0 +1,132 @@
+import { randomUUID } from 'node:crypto';
+
+import { isNonEmptyString } from '@sniptt/guards';
+
+import { runWorkflowActionStep } from 'test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util';
+import { deleteConnectedAccount } from 'test/integration/metadata/suites/connected-account/utils/delete-connected-account.util';
+import { saveImapSmtpCaldavAccount } from 'test/integration/metadata/suites/connected-account/utils/save-imap-smtp-caldav-account.util';
+import { updateConfigVariable } from 'test/integration/twenty-config/utils/update-config-variable.util';
+import { findImportedCalendarEventTitles } from 'test/integration/utils/find-imported-records.util';
+import {
+ type RadicaleServer,
+ startRadicaleContainer,
+} from 'test/integration/utils/start-radicale-container.util';
+
+const HANDLE = `caldav-create-event-action-${randomUUID()}@acme.test`;
+const COLLECTION = 'personal';
+const PASSWORD = 'radicale-password';
+const ATTENDEE = '[email protected]';
+
+const authorizationHeader = `Basic ${Buffer.from(`${HANDLE}:${PASSWORD}`).toString('base64')}`;
+
+describe('CREATE_CALENDAR_EVENT workflow action on CalDAV (integration)', () => {
+ let radicale: RadicaleServer;
+ let connectedAccountId: string;
+
+ const collectionUrl = () =>
+ `http://${radicale.host}:${radicale.port}/${HANDLE}/${COLLECTION}/`;
+
+ beforeAll(async () => {
+ // The CalDAV driver wraps its fetch in the SSRF guard, which rejects the
+ // container's private address before the request is made.
+ await updateConfigVariable({
+ input: { key: 'OUTBOUND_HTTP_SAFE_MODE_ENABLED', value: false },
+ });
+
+ radicale = await startRadicaleContainer({
+ username: HANDLE,
+ password: PASSWORD,
+ });
+
+ await fetch(collectionUrl(), {
+ method: 'MKCOL',
+ headers: {
+ 'Content-Type': 'application/xml; charset=utf-8',
+ Authorization: authorizationHeader,
+ },
+ body: `<?xml version="1.0" encoding="utf-8"?>
+ <mkcol xmlns="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
+ <set><prop>
+ <resourcetype><collection/><c:calendar/></resourcetype>
+ <displayname>Personal</displayname>
+ <c:supported-calendar-component-set><c:comp name="VEVENT"/></c:supported-calendar-component-set>
+ </prop></set>
+ </mkcol>`,
+ });
+
+ const { data } = await saveImapSmtpCaldavAccount({
+ input: {
+ handle: HANDLE,
+ connectionParameters: {
+ CALDAV: {
+ host: `http://${radicale.host}:${radicale.port}`,
+ port: radicale.port,
+ username: HANDLE,
+ password: PASSWORD,
+ },
+ },
+ },
+ expectToFail: false,
+ });
+
+ connectedAccountId = data.connectedAccountId;
+ }, 300000);
+
+ afterAll(async () => {
+ await updateConfigVariable({
+ input: { key: 'OUTBOUND_HTTP_SAFE_MODE_ENABLED', value: true },
+ }).catch(() => undefined);
+
+ if (isNonEmptyString(connectedAccountId)) {
+ await deleteConnectedAccount({
+ id: connectedAccountId,
+ expectToFail: false,
+ }).catch(() => undefined);
+ }
+
+ await radicale?.stop().catch(() => undefined);
+ });
+
+ it('creates an event in the CalDAV collection with a title resolved from the trigger payload', async () => {
+ const title = `CalDAV workflow calendar ${randomUUID()}`;
+
+ const workflowRun = await runWorkflowActionStep({
+ name: 'CalDAV create calendar event workflow',
+ stepType: 'CREATE_CALENDAR_EVENT',
+ input: {
+ connectedAccountId,
+ title: '{{trigger.title}}',
+ description: 'Planning meeting',
+ location: 'Room 101',
+ startsAt: '2026-08-13T09:00:00Z',
+ endsAt: '2026-08-13T10:00:00Z',
+ isFullDay: false,
+ timeZone: 'UTC',
+ attendees: ATTENDEE,
+ sendInvitations: true,
+ addConferencing: false,
+ },
+ payload: { title },
+ });
+
+ expect(workflowRun).toMatchObject({
+ status: 'COMPLETED',
+ stepStatus: 'SUCCESS',
+ });
+ expect(workflowRun.stepResult).toMatchObject({
+ title,
+ iCalUid: expect.any(String),
+ attendeeCount: 1,
+ connectedAccountId,
+ });
+ expect(await findImportedCalendarEventTitles([title])).toEqual([title]);
+
+ const response = await fetch(
+ `${collectionUrl()}${workflowRun.stepResult?.iCalUid}.ics`,
+ { headers: { Authorization: authorizationHeader } },
+ );
+
+ expect(response.status).toBe(200);
+ expect(await response.text()).toContain(`SUMMARY:${title}`);
+ }, 300000);
+});
diff --git a/packages/twenty-server/test/integration/workflow-actions/create-calendar-event/drivers/google-calendar.integration-spec.ts b/packages/twenty-server/test/integration/workflow-actions/create-calendar-event/drivers/google-calendar.integration-spec.ts
new file mode 100644
index 00000000000..fa90eb66ceb
--- /dev/null
+++ b/packages/twenty-server/test/integration/workflow-actions/create-calendar-event/drivers/google-calendar.integration-spec.ts
@@ -0,0 +1,74 @@
+import { randomUUID } from 'node:crypto';
+
+import { ConnectedAccountProvider } from 'twenty-shared/types';
+
+import { setupGoogleMock } from 'test/integration/google/mocks/setup-google-mock.util';
+import { runWorkflowActionStep } from 'test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util';
+import { connectMessagingAccount } from 'test/integration/utils/connect-messaging-account.util';
+import { findImportedCalendarEventTitles } from 'test/integration/utils/find-imported-records.util';
+
+const HANDLE = '[email protected]';
+const ATTENDEE = '[email protected]';
+
+describe('CREATE_CALENDAR_EVENT workflow action on Google Calendar (integration)', () => {
+ const google = setupGoogleMock({ handle: HANDLE });
+
+ let channel: Awaited<ReturnType<typeof connectMessagingAccount>>;
+
+ beforeAll(async () => {
+ channel = await connectMessagingAccount({
+ provider: ConnectedAccountProvider.GOOGLE,
+ handle: HANDLE,
+ });
+ }, 60000);
+
+ afterAll(async () => {
+ await channel?.cleanup().catch(() => undefined);
+ });
+
+ it('creates an event with a title resolved from the trigger payload', async () => {
+ const title = `Gmail workflow calendar ${randomUUID()}`;
+
+ const workflowRun = await runWorkflowActionStep({
+ name: 'Gmail create calendar event workflow',
+ stepType: 'CREATE_CALENDAR_EVENT',
+ input: {
+ connectedAccountId: channel.connectedAccountId,
+ title: '{{trigger.title}}',
+ description: 'Planning meeting',
+ location: 'Room 101',
+ startsAt: '2026-08-13T09:00:00Z',
+ endsAt: '2026-08-13T10:00:00Z',
+ isFullDay: false,
+ timeZone: 'UTC',
+ attendees: ATTENDEE,
+ sendInvitations: true,
+ addConferencing: true,
+ },
+ payload: { title },
+ });
+
+ expect(workflowRun).toMatchObject({
+ status: 'COMPLETED',
+ stepStatus: 'SUCCESS',
+ });
+ expect(workflowRun.stepResult).toMatchObject({
+ title,
+ iCalUid: expect.stringContaining('@google.com'),
+ attendeeCount: 1,
+ connectedAccountId: channel.connectedAccountId,
+ });
+ expect(google.createdCalendarEvents).toEqual([
+ expect.objectContaining({
+ summary: title,
+ description: 'Planning meeting',
+ location: 'Room 101',
+ attendees: [expect.objectContaining({ email: ATTENDEE })],
+ conferenceData: expect.objectContaining({
+ createRequest: expect.any(Object),
+ }),
+ }),
+ ]);
+ expect(await findImportedCalendarEventTitles([title])).toEqual([title]);
+ }, 60000);
+});
diff --git a/packages/twenty-server/test/integration/workflow-actions/create-calendar-event/drivers/microsoft-calendar.integration-spec.ts b/packages/twenty-server/test/integration/workflow-actions/create-calendar-event/drivers/microsoft-calendar.integration-spec.ts
new file mode 100644
index 00000000000..ff50f0e160c
--- /dev/null
+++ b/packages/twenty-server/test/integration/workflow-actions/create-calendar-event/drivers/microsoft-calendar.integration-spec.ts
@@ -0,0 +1,72 @@
+import { randomUUID } from 'node:crypto';
+
+import { ConnectedAccountProvider } from 'twenty-shared/types';
+
+import { runWorkflowActionStep } from 'test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util';
+import { setupMicrosoftMock } from 'test/integration/microsoft/mocks/setup-microsoft-mock.util';
+import { connectMessagingAccount } from 'test/integration/utils/connect-messaging-account.util';
+import { findImportedCalendarEventTitles } from 'test/integration/utils/find-imported-records.util';
+
+const HANDLE = '[email protected]';
+const ATTENDEE = '[email protected]';
+
+describe('CREATE_CALENDAR_EVENT workflow action on Microsoft Calendar (integration)', () => {
+ const microsoft = setupMicrosoftMock({ handle: HANDLE });
+
+ let channel: Awaited<ReturnType<typeof connectMessagingAccount>>;
+
+ beforeAll(async () => {
+ channel = await connectMessagingAccount({
+ provider: ConnectedAccountProvider.MICROSOFT,
+ handle: HANDLE,
+ });
+ }, 60000);
+
+ afterAll(async () => {
+ await channel?.cleanup().catch(() => undefined);
+ });
+
+ it('creates an event with a title resolved from the trigger payload', async () => {
+ const title = `Microsoft workflow calendar ${randomUUID()}`;
+
+ const workflowRun = await runWorkflowActionStep({
+ name: 'Microsoft create calendar event workflow',
+ stepType: 'CREATE_CALENDAR_EVENT',
+ input: {
+ connectedAccountId: channel.connectedAccountId,
+ title: '{{trigger.title}}',
+ description: 'Planning meeting',
+ location: 'Room 101',
+ startsAt: '2026-08-13T09:00:00Z',
+ endsAt: '2026-08-13T10:00:00Z',
+ isFullDay: false,
+ timeZone: 'UTC',
+ attendees: ATTENDEE,
+ sendInvitations: true,
+ addConferencing: true,
+ },
+ payload: { title },
+ });
+
+ expect(workflowRun).toMatchObject({
+ status: 'COMPLETED',
+ stepStatus: 'SUCCESS',
+ });
+ expect(workflowRun.stepResult).toMatchObject({
+ title,
+ iCalUid: expect.stringContaining('@microsoft.com'),
+ attendeeCount: 1,
+ connectedAccountId: channel.connectedAccountId,
+ });
+ expect(microsoft.createdCalendarEvents).toEqual([
+ expect.objectContaining({
+ subject: title,
+ location: { displayName: 'Room 101' },
+ attendees: [{ emailAddress: { address: ATTENDEE }, type: 'required' }],
+ isOnlineMeeting: true,
+ onlineMeetingProvider: 'teamsForBusiness',
+ }),
+ ]);
+ expect(await findImportedCalendarEventTitles([title])).toEqual([title]);
+ }, 60000);
+});
diff --git a/packages/twenty-server/test/integration/workflow-actions/draft-email/drivers/gmail.integration-spec.ts b/packages/twenty-server/test/integration/workflow-actions/draft-email/drivers/gmail.integration-spec.ts
new file mode 100644
index 00000000000..647b03a76e3
--- /dev/null
+++ b/packages/twenty-server/test/integration/workflow-actions/draft-email/drivers/gmail.integration-spec.ts
@@ -0,0 +1,83 @@
+import { randomUUID } from 'node:crypto';
+
+import { ConnectedAccountProvider } from 'twenty-shared/types';
+
+import { setupGoogleMock } from 'test/integration/google/mocks/setup-google-mock.util';
+import { runWorkflowActionStep } from 'test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util';
+import { connectMessagingAccount } from 'test/integration/utils/connect-messaging-account.util';
+import { findRecordNodesByFilter } from 'test/integration/utils/find-records-by-filter.util';
+
+const HANDLE = '[email protected]';
+const RECIPIENTS = {
+};
+
+describe('DRAFT_EMAIL workflow action on Gmail (integration)', () => {
+ const google = setupGoogleMock({ handle: HANDLE });
+
+ let channel: Awaited<ReturnType<typeof connectMessagingAccount>>;
+
+ beforeAll(async () => {
+ channel = await connectMessagingAccount({
+ provider: ConnectedAccountProvider.GOOGLE,
+ handle: HANDLE,
+ });
+ }, 60000);
+
+ afterAll(async () => {
+ await channel?.cleanup().catch(() => undefined);
+ });
+
+ it('creates a draft without sending or persisting it', async () => {
+ const subject = `Gmail workflow draft ${randomUUID()}`;
+
+ const workflowRun = await runWorkflowActionStep({
+ name: 'Gmail draft email workflow',
+ stepType: 'DRAFT_EMAIL',
+ input: {
+ connectedAccountId: channel.connectedAccountId,
+ recipients: {
+ to: '{{trigger.to}}',
+ cc: '{{trigger.cc}}',
+ bcc: '{{trigger.bcc}}',
+ },
+ subject: '{{trigger.subject}}',
+ body: '<p>Gmail workflow draft body</p>',
+ },
+ payload: { ...RECIPIENTS, subject },
+ });
+
+ expect(workflowRun).toMatchObject({
+ status: 'COMPLETED',
+ stepStatus: 'SUCCESS',
+ });
+ expect(workflowRun.stepResult).toMatchObject({
+ recipients: [RECIPIENTS.to],
+ ccRecipients: [RECIPIENTS.cc],
+ bccRecipients: [RECIPIENTS.bcc],
+ subject,
+ connectedAccountId: channel.connectedAccountId,
+ });
+ expect(google.draftMessages).toHaveLength(1);
+
+ const [{ raw }] = google.draftMessages;
+
+ expect(raw).toContain(`To: ${RECIPIENTS.to}`);
+ expect(raw).toContain(`Cc: ${RECIPIENTS.cc}`);
+ expect(raw).toContain(`Bcc: ${RECIPIENTS.bcc}`);
+ expect(raw).toContain(`Subject: ${subject}`);
+ expect(google.sentMessages).toEqual([]);
+ expect(
+ await findRecordNodesByFilter<{ id: string }>(
+ 'message',
+ 'messages',
+ 'id',
+ {
+ subject: { eq: subject },
+ },
+ ),
+ ).toEqual([]);
+ }, 60000);
+});
diff --git a/packages/twenty-server/test/integration/workflow-actions/draft-email/drivers/imap-smtp.integration-spec.ts b/packages/twenty-server/test/integration/workflow-actions/draft-email/drivers/imap-smtp.integration-spec.ts
new file mode 100644
index 00000000000..d573200ebab
--- /dev/null
+++ b/packages/twenty-server/test/integration/workflow-actions/draft-email/drivers/imap-smtp.integration-spec.ts
@@ -0,0 +1,155 @@
+import { randomUUID } from 'node:crypto';
+
+import { isNonEmptyString } from '@sniptt/guards';
+import { ImapFlow } from 'imapflow';
+
+import { EmailConnectionSecurity } from 'src/engine/core-modules/imap-smtp-caldav-connection/enums/email-connection-security.enum';
+import { MessageChannelEntity } from 'src/engine/metadata-modules/message-channel/entities/message-channel.entity';
+
+import { runWorkflowActionStep } from 'test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util';
+import { deleteConnectedAccount } from 'test/integration/metadata/suites/connected-account/utils/delete-connected-account.util';
+import { saveImapSmtpCaldavAccount } from 'test/integration/metadata/suites/connected-account/utils/save-imap-smtp-caldav-account.util';
+import { updateConfigVariable } from 'test/integration/twenty-config/utils/update-config-variable.util';
+import { findRecordNodesByFilter } from 'test/integration/utils/find-records-by-filter.util';
+import { getCoreRepository } from 'test/integration/utils/get-core-repository.util';
+import { runMessageChannelSync } from 'test/integration/utils/run-message-channel-sync.util';
+import {
+ type GreenmailServer,
+ startGreenmailContainer,
+} from 'test/integration/utils/start-greenmail-container.util';
+
+const PASSWORD = 'greenmail-password';
+const HANDLE = `imap-draft-email-action-${randomUUID()}@acme.test`;
+
+describe('DRAFT_EMAIL workflow action on IMAP (integration)', () => {
+ let greenmail: GreenmailServer;
+ let connectedAccountId: string;
+ let messageChannelId: string;
+
+ const findDraftSubjects = async (): Promise<string[]> => {
+ const client = new ImapFlow({
+ host: greenmail.host,
+ port: greenmail.imapPort,
+ secure: false,
+ auth: { user: HANDLE.split('@')[0], pass: PASSWORD },
+ logger: false,
+ });
+
+ await client.connect();
+
+ try {
+ const { exists } = await client.mailboxOpen('Drafts');
+
+ if (exists === 0) {
+ return [];
+ }
+
+ const subjects: string[] = [];
+
+ for await (const message of client.fetch('1:*', { envelope: true })) {
+ const subject = message.envelope?.subject;
+
+ if (isNonEmptyString(subject)) {
+ subjects.push(subject);
+ }
+ }
+
+ return subjects;
+ } finally {
+ await client.logout();
+ }
+ };
+
+ beforeAll(async () => {
+ await updateConfigVariable({
+ input: { key: 'OUTBOUND_HTTP_SAFE_MODE_ENABLED', value: false },
+ });
+
+ greenmail = await startGreenmailContainer({
+ username: HANDLE,
+ password: PASSWORD,
+ });
+
+ const { data } = await saveImapSmtpCaldavAccount({
+ input: {
+ handle: HANDLE,
+ connectionParameters: {
+ IMAP: {
+ host: greenmail.host,
+ port: greenmail.imapPort,
+ username: HANDLE.split('@')[0],
+ password: PASSWORD,
+ connectionSecurity: EmailConnectionSecurity.NONE,
+ },
+ SMTP: {
+ host: greenmail.host,
+ port: greenmail.smtpPort,
+ username: HANDLE.split('@')[0],
+ password: PASSWORD,
+ connectionSecurity: EmailConnectionSecurity.NONE,
+ },
+ },
+ },
+ expectToFail: false,
+ });
+
+ connectedAccountId = data.connectedAccountId;
+ messageChannelId = (
+ await getCoreRepository<MessageChannelEntity>(
+ MessageChannelEntity,
+ ).findOneByOrFail({ connectedAccountId })
+ ).id;
+
+ await runMessageChannelSync(messageChannelId);
+ }, 300000);
+
+ afterAll(async () => {
+ await updateConfigVariable({
+ input: { key: 'OUTBOUND_HTTP_SAFE_MODE_ENABLED', value: true },
+ }).catch(() => undefined);
+
+ if (isNonEmptyString(connectedAccountId)) {
+ await deleteConnectedAccount({
+ id: connectedAccountId,
+ expectToFail: false,
+ }).catch(() => undefined);
+ }
+
+ await greenmail?.stop().catch(() => undefined);
+ });
+
+ it('appends a draft to the drafts folder without persisting it', async () => {
+ const subject = `IMAP/SMTP workflow draft ${randomUUID()}`;
+
+ const workflowRun = await runWorkflowActionStep({
+ name: 'IMAP/SMTP draft email workflow',
+ stepType: 'DRAFT_EMAIL',
+ input: {
+ connectedAccountId,
+ recipients: { to: '{{trigger.to}}' },
+ subject: '{{trigger.subject}}',
+ body: '<p>SMTP workflow draft body</p>',
+ },
+ payload: { to: HANDLE, subject },
+ });
+
+ expect(workflowRun).toMatchObject({
+ status: 'COMPLETED',
+ stepStatus: 'SUCCESS',
+ });
+ expect(workflowRun.stepResult).toMatchObject({
+ recipients: [HANDLE],
+ subject,
+ connectedAccountId,
+ });
+ expect(await findDraftSubjects()).toContain(subject);
+ expect(
+ await findRecordNodesByFilter<{ id: string }>(
+ 'message',
+ 'messages',
+ 'id',
+ { subject: { eq: subject } },
+ ),
+ ).toEqual([]);
+ }, 300000);
+});
diff --git a/packages/twenty-server/test/integration/workflow-actions/draft-email/drivers/microsoft.integration-spec.ts b/packages/twenty-server/test/integration/workflow-actions/draft-email/drivers/microsoft.integration-spec.ts
new file mode 100644
index 00000000000..5bbc06c8a42
--- /dev/null
+++ b/packages/twenty-server/test/integration/workflow-actions/draft-email/drivers/microsoft.integration-spec.ts
@@ -0,0 +1,83 @@
+import { randomUUID } from 'node:crypto';
+
+import { ConnectedAccountProvider } from 'twenty-shared/types';
+
+import { runWorkflowActionStep } from 'test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util';
+import { setupMicrosoftMock } from 'test/integration/microsoft/mocks/setup-microsoft-mock.util';
+import { connectMessagingAccount } from 'test/integration/utils/connect-messaging-account.util';
+import { findRecordNodesByFilter } from 'test/integration/utils/find-records-by-filter.util';
+
+const HANDLE = '[email protected]';
+const RECIPIENTS = {
+};
+
+describe('DRAFT_EMAIL workflow action on Microsoft (integration)', () => {
+ const microsoft = setupMicrosoftMock({ handle: HANDLE });
+
+ let channel: Awaited<ReturnType<typeof connectMessagingAccount>>;
+
+ beforeAll(async () => {
+ channel = await connectMessagingAccount({
+ provider: ConnectedAccountProvider.MICROSOFT,
+ handle: HANDLE,
+ });
+ }, 60000);
+
+ afterAll(async () => {
+ await channel?.cleanup().catch(() => undefined);
+ });
+
+ it('creates a draft without sending or persisting it', async () => {
+ const subject = `Microsoft workflow draft ${randomUUID()}`;
+
+ const workflowRun = await runWorkflowActionStep({
+ name: 'Microsoft draft email workflow',
+ stepType: 'DRAFT_EMAIL',
+ input: {
+ connectedAccountId: channel.connectedAccountId,
+ recipients: {
+ to: '{{trigger.to}}',
+ cc: '{{trigger.cc}}',
+ bcc: '{{trigger.bcc}}',
+ },
+ subject: '{{trigger.subject}}',
+ body: '<p>Microsoft workflow draft body</p>',
+ },
+ payload: { ...RECIPIENTS, subject },
+ });
+
+ expect(workflowRun).toMatchObject({
+ status: 'COMPLETED',
+ stepStatus: 'SUCCESS',
+ });
+ expect(workflowRun.stepResult).toMatchObject({
+ recipients: [RECIPIENTS.to],
+ ccRecipients: [RECIPIENTS.cc],
+ bccRecipients: [RECIPIENTS.bcc],
+ subject,
+ connectedAccountId: channel.connectedAccountId,
+ });
+ expect(microsoft.createdMessages).toEqual([
+ expect.objectContaining({
+ subject,
+ toRecipients: [{ emailAddress: { address: RECIPIENTS.to } }],
+ ccRecipients: [{ emailAddress: { address: RECIPIENTS.cc } }],
+ bccRecipients: [{ emailAddress: { address: RECIPIENTS.bcc } }],
+ }),
+ ]);
+ expect(microsoft.sentMessageIds).toEqual([]);
+ expect(
+ await findRecordNodesByFilter<{ id: string }>(
+ 'message',
+ 'messages',
+ 'id',
+ {
+ subject: { eq: subject },
+ },
+ ),
+ ).toEqual([]);
+ }, 60000);
+});
diff --git a/packages/twenty-server/test/integration/workflow-actions/send-email/drivers/gmail.integration-spec.ts b/packages/twenty-server/test/integration/workflow-actions/send-email/drivers/gmail.integration-spec.ts
new file mode 100644
index 00000000000..af2cb57c67e
--- /dev/null
+++ b/packages/twenty-server/test/integration/workflow-actions/send-email/drivers/gmail.integration-spec.ts
@@ -0,0 +1,111 @@
+import { randomUUID } from 'node:crypto';
+
+import { ConnectedAccountProvider } from 'twenty-shared/types';
+
+import { setupGoogleMock } from 'test/integration/google/mocks/setup-google-mock.util';
+import { runWorkflowActionStep } from 'test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util';
+import { connectMessagingAccount } from 'test/integration/utils/connect-messaging-account.util';
+import { findRecordNodesByFilter } from 'test/integration/utils/find-records-by-filter.util';
+
+const HANDLE = '[email protected]';
+const RECIPIENTS = {
+};
+
+describe('SEND_EMAIL workflow action on Gmail (integration)', () => {
+ const google = setupGoogleMock({ handle: HANDLE });
+
+ let channel: Awaited<ReturnType<typeof connectMessagingAccount>>;
+
+ beforeAll(async () => {
+ channel = await connectMessagingAccount({
+ provider: ConnectedAccountProvider.GOOGLE,
+ handle: HANDLE,
+ });
+ }, 60000);
+
+ afterAll(async () => {
+ await channel?.cleanup().catch(() => undefined);
+ });
+
+ it('sends an email with recipients resolved from the trigger payload', async () => {
+ const subject = `Gmail workflow send ${randomUUID()}`;
+
+ const workflowRun = await runWorkflowActionStep({
+ name: 'Gmail send email workflow',
+ stepType: 'SEND_EMAIL',
+ input: {
+ connectedAccountId: channel.connectedAccountId,
+ recipients: {
+ to: '{{trigger.to}}',
+ cc: '{{trigger.cc}}',
+ bcc: '{{trigger.bcc}}',
+ },
+ subject: '{{trigger.subject}}',
+ body: '<p>Gmail workflow body</p>',
+ },
+ payload: { ...RECIPIENTS, subject },
+ });
+
+ expect(workflowRun).toMatchObject({
+ status: 'COMPLETED',
+ stepStatus: 'SUCCESS',
+ });
+ expect(workflowRun.stepResult).toMatchObject({
+ recipients: [RECIPIENTS.to],
+ ccRecipients: [RECIPIENTS.cc],
+ bccRecipients: [RECIPIENTS.bcc],
+ subject,
+ connectedAccountId: channel.connectedAccountId,
+ messageId: expect.any(String),
+ messageThreadId: expect.any(String),
+ });
+ expect(google.sentMessages).toHaveLength(1);
+
+ const [{ raw }] = google.sentMessages;
+
+ expect(raw).toContain(`To: ${RECIPIENTS.to}`);
+ expect(raw).toContain(`Cc: ${RECIPIENTS.cc}`);
+ expect(raw).toContain(`Bcc: ${RECIPIENTS.bcc}`);
+ expect(raw).toContain(`Subject: ${subject}`);
+
+ const [message] = await findRecordNodesByFilter<{
+ id: string;
+ isDraft: boolean;
+ text: string | null;
+ }>('message', 'messages', 'id isDraft text', {
+ subject: { eq: subject },
+ });
+
+ expect(message).toMatchObject({
+ isDraft: false,
+ text: 'Gmail workflow body',
+ });
+ expect(
+ await findRecordNodesByFilter<{ messageChannelId: string }>(
+ 'messageChannelMessageAssociation',
+ 'messageChannelMessageAssociations',
+ 'messageChannelId',
+ { messageId: { eq: message.id } },
+ ),
+ ).toEqual([
+ expect.objectContaining({ messageChannelId: channel.channelId }),
+ ]);
+ expect(
+ await findRecordNodesByFilter<{ handle: string; role: string }>(
+ 'messageParticipant',
+ 'messageParticipants',
+ 'handle role',
+ { messageId: { eq: message.id } },
+ ),
+ ).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({ handle: RECIPIENTS.to, role: 'TO' }),
+ expect.objectContaining({ handle: RECIPIENTS.cc, role: 'CC' }),
+ expect.objectContaining({ handle: RECIPIENTS.bcc, role: 'BCC' }),
+ ]),
+ );
+ }, 60000);
+});
diff --git a/packages/twenty-server/test/integration/workflow-actions/send-email/drivers/imap-smtp.integration-spec.ts b/packages/twenty-server/test/integration/workflow-actions/send-email/drivers/imap-smtp.integration-spec.ts
new file mode 100644
index 00000000000..5cf542f7df6
--- /dev/null
+++ b/packages/twenty-server/test/integration/workflow-actions/send-email/drivers/imap-smtp.integration-spec.ts
@@ -0,0 +1,154 @@
+import { randomUUID } from 'node:crypto';
+
+import { isNonEmptyString } from '@sniptt/guards';
+
+import { EmailConnectionSecurity } from 'src/engine/core-modules/imap-smtp-caldav-connection/enums/email-connection-security.enum';
+import { MessageChannelEntity } from 'src/engine/metadata-modules/message-channel/entities/message-channel.entity';
+
+import { runWorkflowActionStep } from 'test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util';
+import { deleteConnectedAccount } from 'test/integration/metadata/suites/connected-account/utils/delete-connected-account.util';
+import { saveImapSmtpCaldavAccount } from 'test/integration/metadata/suites/connected-account/utils/save-imap-smtp-caldav-account.util';
+import { updateConfigVariable } from 'test/integration/twenty-config/utils/update-config-variable.util';
+import { findRecordNodesByFilter } from 'test/integration/utils/find-records-by-filter.util';
+import { getCoreRepository } from 'test/integration/utils/get-core-repository.util';
+import { runMessageChannelSync } from 'test/integration/utils/run-message-channel-sync.util';
+import {
+ type GreenmailServer,
+ startGreenmailContainer,
+} from 'test/integration/utils/start-greenmail-container.util';
+
+const PASSWORD = 'greenmail-password';
+const HANDLE = `smtp-send-email-action-${randomUUID()}@acme.test`;
+
+describe('SEND_EMAIL workflow action on SMTP (integration)', () => {
+ let greenmail: GreenmailServer;
+ let connectedAccountId: string;
+ let messageChannelId: string;
+
+ beforeAll(async () => {
+ await updateConfigVariable({
+ input: { key: 'OUTBOUND_HTTP_SAFE_MODE_ENABLED', value: false },
+ });
+
+ greenmail = await startGreenmailContainer({
+ username: HANDLE,
+ password: PASSWORD,
+ });
+
+ const { data } = await saveImapSmtpCaldavAccount({
+ input: {
+ handle: HANDLE,
+ connectionParameters: {
+ IMAP: {
+ host: greenmail.host,
+ port: greenmail.imapPort,
+ username: HANDLE.split('@')[0],
+ password: PASSWORD,
+ connectionSecurity: EmailConnectionSecurity.NONE,
+ },
+ SMTP: {
+ host: greenmail.host,
+ port: greenmail.smtpPort,
+ username: HANDLE.split('@')[0],
+ password: PASSWORD,
+ connectionSecurity: EmailConnectionSecurity.NONE,
+ },
+ },
+ },
+ expectToFail: false,
+ });
+
+ connectedAccountId = data.connectedAccountId;
+ messageChannelId = (
+ await getCoreRepository<MessageChannelEntity>(
+ MessageChannelEntity,
+ ).findOneByOrFail({ connectedAccountId })
+ ).id;
+
+ await runMessageChannelSync(messageChannelId);
+ }, 300000);
+
+ afterAll(async () => {
+ await updateConfigVariable({
+ input: { key: 'OUTBOUND_HTTP_SAFE_MODE_ENABLED', value: true },
+ }).catch(() => undefined);
+
+ if (isNonEmptyString(connectedAccountId)) {
+ await deleteConnectedAccount({
+ id: connectedAccountId,
+ expectToFail: false,
+ }).catch(() => undefined);
+ }
+
+ await greenmail?.stop().catch(() => undefined);
+ });
+
+ it('sends an email over SMTP and persists it', async () => {
+ const subject = `IMAP/SMTP workflow send ${randomUUID()}`;
+
+ const workflowRun = await runWorkflowActionStep({
+ name: 'IMAP/SMTP send email workflow',
+ stepType: 'SEND_EMAIL',
+ input: {
+ connectedAccountId,
+ recipients: {
+ to: '{{trigger.to}}',
+ cc: '{{trigger.cc}}',
+ bcc: '{{trigger.bcc}}',
+ },
+ subject: '{{trigger.subject}}',
+ body: '<p>SMTP workflow body</p>',
+ },
+ payload: { to: HANDLE, cc: HANDLE, bcc: HANDLE, subject },
+ });
+
+ expect(workflowRun).toMatchObject({
+ status: 'COMPLETED',
+ stepStatus: 'SUCCESS',
+ });
+ expect(workflowRun.stepResult).toMatchObject({
+ recipients: [HANDLE],
+ ccRecipients: [HANDLE],
+ bccRecipients: [HANDLE],
+ subject,
+ connectedAccountId,
+ messageId: expect.any(String),
+ messageThreadId: expect.any(String),
+ });
+
+ const [message] = await findRecordNodesByFilter<{
+ id: string;
+ isDraft: boolean;
+ text: string | null;
+ }>('message', 'messages', 'id isDraft text', {
+ subject: { eq: subject },
+ });
+
+ expect(message).toMatchObject({
+ isDraft: false,
+ text: 'SMTP workflow body',
+ });
+ expect(
+ await findRecordNodesByFilter<{ messageChannelId: string }>(
+ 'messageChannelMessageAssociation',
+ 'messageChannelMessageAssociations',
+ 'messageChannelId',
+ { messageId: { eq: message.id } },
+ ),
+ ).toEqual([expect.objectContaining({ messageChannelId })]);
+ expect(
+ await findRecordNodesByFilter<{ handle: string; role: string }>(
+ 'messageParticipant',
+ 'messageParticipants',
+ 'handle role',
+ { messageId: { eq: message.id } },
+ ),
+ ).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({ handle: HANDLE, role: 'TO' }),
+ expect.objectContaining({ handle: HANDLE, role: 'CC' }),
+ expect.objectContaining({ handle: HANDLE, role: 'BCC' }),
+ ]),
+ );
+ }, 300000);
+});
diff --git a/packages/twenty-server/test/integration/workflow-actions/send-email/drivers/microsoft.integration-spec.ts b/packages/twenty-server/test/integration/workflow-actions/send-email/drivers/microsoft.integration-spec.ts
new file mode 100644
index 00000000000..809e74b7bd1
--- /dev/null
+++ b/packages/twenty-server/test/integration/workflow-actions/send-email/drivers/microsoft.integration-spec.ts
@@ -0,0 +1,118 @@
+import { randomUUID } from 'node:crypto';
+
+import { ConnectedAccountProvider } from 'twenty-shared/types';
+
+import { runWorkflowActionStep } from 'test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util';
+import { setupMicrosoftMock } from 'test/integration/microsoft/mocks/setup-microsoft-mock.util';
+import { connectMessagingAccount } from 'test/integration/utils/connect-messaging-account.util';
+import { findRecordNodesByFilter } from 'test/integration/utils/find-records-by-filter.util';
+
+const HANDLE = '[email protected]';
+const RECIPIENTS = {
+};
+
+describe('SEND_EMAIL workflow action on Microsoft (integration)', () => {
+ const microsoft = setupMicrosoftMock({ handle: HANDLE });
+
+ let channel: Awaited<ReturnType<typeof connectMessagingAccount>>;
+
+ beforeAll(async () => {
+ channel = await connectMessagingAccount({
+ provider: ConnectedAccountProvider.MICROSOFT,
+ handle: HANDLE,
+ });
+ }, 60000);
+
+ afterAll(async () => {
+ await channel?.cleanup().catch(() => undefined);
+ });
+
+ it('sends an email with recipients resolved from the trigger payload', async () => {
+ const subject = `Microsoft workflow send ${randomUUID()}`;
+
+ const workflowRun = await runWorkflowActionStep({
+ name: 'Microsoft send email workflow',
+ stepType: 'SEND_EMAIL',
+ input: {
+ connectedAccountId: channel.connectedAccountId,
+ recipients: {
+ to: '{{trigger.to}}',
+ cc: '{{trigger.cc}}',
+ bcc: '{{trigger.bcc}}',
+ },
+ subject: '{{trigger.subject}}',
+ body: '<p>Microsoft workflow body</p>',
+ },
+ payload: { ...RECIPIENTS, subject },
+ });
+
+ expect(workflowRun).toMatchObject({
+ status: 'COMPLETED',
+ stepStatus: 'SUCCESS',
+ });
+ expect(workflowRun.stepResult).toMatchObject({
+ recipients: [RECIPIENTS.to],
+ ccRecipients: [RECIPIENTS.cc],
+ bccRecipients: [RECIPIENTS.bcc],
+ subject,
+ connectedAccountId: channel.connectedAccountId,
+ messageId: expect.any(String),
+ messageThreadId: expect.any(String),
+ });
+ expect(microsoft.createdMessages).toEqual([
+ expect.objectContaining({
+ subject,
+ toRecipients: [{ emailAddress: { address: RECIPIENTS.to } }],
+ ccRecipients: [{ emailAddress: { address: RECIPIENTS.cc } }],
+ bccRecipients: [{ emailAddress: { address: RECIPIENTS.bcc } }],
+ }),
+ ]);
+ expect(microsoft.sentMessageIds).toEqual(['microsoft-message-1']);
+
+ const [message] = await findRecordNodesByFilter<{
+ id: string;
+ isDraft: boolean;
+ text: string | null;
+ }>('message', 'messages', 'id isDraft text', {
+ subject: { eq: subject },
+ });
+
+ expect(message).toMatchObject({
+ isDraft: false,
+ text: 'Microsoft workflow body',
+ });
+ expect(
+ await findRecordNodesByFilter<{
+ messageChannelId: string;
+ messageExternalId: string;
+ }>(
+ 'messageChannelMessageAssociation',
+ 'messageChannelMessageAssociations',
+ 'messageChannelId messageExternalId',
+ { messageId: { eq: message.id } },
+ ),
+ ).toEqual([
+ expect.objectContaining({
+ messageChannelId: channel.channelId,
+ messageExternalId: 'microsoft-message-1',
+ }),
+ ]);
+ expect(
+ await findRecordNodesByFilter<{ handle: string; role: string }>(
+ 'messageParticipant',
+ 'messageParticipants',
+ 'handle role',
+ { messageId: { eq: message.id } },
+ ),
+ ).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({ handle: RECIPIENTS.to, role: 'TO' }),
+ expect.objectContaining({ handle: RECIPIENTS.cc, role: 'CC' }),
+ expect.objectContaining({ handle: RECIPIENTS.bcc, role: 'BCC' }),
+ ]),
+ );
+ }, 60000);
+});