Skip to content

Send campaigns through a sender service - #32468

Open
neo773 wants to merge 1 commit into
mainfrom
neo773/campaign-sender-refactor
Open

neo773 wants to merge 1 commit into
mainfrom
neo773/campaign-sender-refactor

Conversation

@neo773

@neo773 neo773 commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Groundwork for sending campaigns from a personal inbox. Nothing changes for users: campaigns still go out from a shared inbox on a verified domain.

Types

Sender. A campaign is sent through the connected account of its channel. CampaignSenderService switches on the provider; only the shared inbox case exists here.

type CampaignBatch = Pick<
  EmailingDomainSendEmailBatchInput,
  'template' | 'recipients' | 'unsubscribeTopicId'
>

CampaignSenderService.sendBatch({
  campaignBatch: CampaignBatch,
  connectedAccount: ConnectedAccountEntity,
}): Promise<EmailingDomainSendEmailBatchResult>

CampaignSenderValidationService.findSendReadyEmailingDomainOrThrow({ workspaceId, fromAddress }): Promise<EmailingDomainEntity>

MessageChannelMetadataService.findCampaignChannel({ fromAddress, workspaceId }): Promise<MessageChannelEntity | null>

Job data. The domain is found from the campaign's from address, so its id no longer goes through every job.

  type PreparedCampaignSend
  type MaterializeCampaignJobData
  type MaterializeCampaignChunkJobData
  type SendCampaignEmailBatchJobData
-   emailingDomainId: string

Unsubscribed recipients. The batch job skips them before calling the sender, so the separate result type is gone. findBlockedRecipientAddresses moves to MessageSuppressionService.

- type CampaignBatchSendOutcome

Links. Unsubscribe and tracking links use the domain's own hostname when it has one, otherwise the workspace's public domain or the server URL. The log driver used in development gets its links from here too.

RecipientLinksService.getBaseUrl({ workspaceId, fromAddress }): Promise<string>

Modules. EmailingDomainSenderModule holds the emailing domain sender, suppression and topic services, so the outbound messaging module no longer imports the whole emailing module.

Blast radius

  • Database: no migration.
  • API: unchanged.
  • Campaigns: same provider and same domain checks. The domain is looked up by from address instead of by id. Unsubscribed recipients are marked skipped by the batch job instead of by the sender.
  • Log driver (development only): links use the workspace's public domain or the server URL.
  • Deploy: campaign jobs queued before the deploy still run; their old domain id is ignored.
  • Rollout: no feature flag.

@neo773
neo773 added this pull request to stack #32469 December 5, 2026 11:30
@neo773 neo773 changed the title neo773/campaign sender refactor Send campaigns through a sender service Dec 5, 2026
@neo773
neo773 marked this pull request as ready for review December 5, 2026 11:35
@twenty-ci-bot-public

Copy link
Copy Markdown

🤖 PR Review

Check Result
🔍 Build safety ⏭️ skipped — external-only
🧭 Triage ⏭️ skipped — external-only
📐 Quality ✅ passed — 4 nit(s)
🛡️ Security ✅ passed
🚦 Auto-approve 👀 needs review — Complexity is high
🔐 Permissions ⏭️ skipped: no endpoint permission change

🛡️ Security Review

✅ No high-severity vulnerabilities detected.


🚦 Auto-approve

🙋 Manual review recommended for the following reason(s):

  • Complexity is high

  • 🧠 Complexity: high

  • 📏 Size: +477 / -398 lines across 23 file(s)


View details

Automated pre-review — human approval still required.

@twenty-ci-bot-public

Copy link
Copy Markdown

🟡 Quality review · 4 findings

Safe to merge: two non-blocking architecture concerns, both about where invariants live

High-level — No PR description was staged to reconcile against; the refactor (sender module split, provider dispatch, suppression moved to batch delivery) is reasonably scoped at ~800 changed lines, but it adds a second recipient-link URL resolver with a silent fallback and removes the suppression guard from the sender handoff.
Low-level — 2 rule violations found — 903 rule questions over 17 piece(s) of 16 file(s)

💬 4 inline comments on the diff.


Reviewed against the pr-review standard — high-level then low-level. Advisory; human review still required. Run details.

});

return (
this.workspaceDomainsService.buildPublicFunctionBaseUrl({ workspace }) ??

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit · High-level · one source of truth

RecipientLinksService adds a second resolver for the recipient-link host next to getUnsubscribeBaseUrl, and it silently falls back to the workspace public URL or SERVER_URL

Before this PR, tracking was skipped when the domain had no active unsubscribe hostname. Now Resend/SES campaigns can carry click and open links on the shared instance host, while their unsubscribe links still come from drivers/utils/get-unsubscribe-base-url.util.ts, which throws in that same case. Use one resolver for both, or keep the strict no-hostname behaviour for non-LOG drivers so tracking and unsubscribe links always agree on the host.

@@ -87,125 +87,47 @@ export class EmailingDomainSenderService {

async sendEmailBatch({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit · High-level · engineering architecture

EmailingDomainSenderService.sendEmailBatch no longer enforces suppression at the handoff, which moves an opt-out guarantee from the sender to each caller

sendEmailBatch is now exported through EmailingDomainSenderModule to messaging too, and any future caller that skips MessageSuppressionService.findBlockedRecipientAddresses will mail unsubscribed recipients. Keep the blocked-address filter in the sender (or in CampaignSenderService), so every send path enforces it.

connectedAccount,
}: {
campaignBatch: CampaignBatch;
connectedAccount: ConnectedAccountEntity;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit · Low-level · Narrow object parameters to the fields read

The parameter is typed as the whole ConnectedAccountEntity, but sendBatch only reads provider, workspaceId and handle; it should be Pick<ConnectedAccountEntity, 'provider' | 'workspaceId' | 'handle'>.

sendKind,
emailAddresses: recipients.map((recipient) => recipient.email),
unsubscribeTopicId,
where: { domain: getDomainFromEmail(from)?.toLowerCase() },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit · Low-level · No silent failures or permissive fallbacks

If getDomainFromEmail(from) returns undefined, the ?. yields { domain: undefined }, which TypeORM drops from the filter, so findOne can return an arbitrary emailing domain in the workspace instead of failing.

@greptile-apps

greptile-apps Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Routes campaign batches through CampaignSenderService, which currently supports shared inboxes only.

  • Campaign batches now send through the connected account selected for their from address.
  • Campaign links use a URL chosen for their sender and workspace.

No actionable issues were found. The inspected callers in dependent PR #32388 use the updated APIs.

Diagram

%%{init: {'theme': 'neutral', 'htmlLabels': false}}%%
flowchart TD
  A[Campaign batch job] --> B[Find campaign channel]
  B --> C[Prepare content and recipient links]
  C --> D[Check suppressions again]
  D --> E[Mark blocked recipients skipped]
  D --> F[CampaignSenderService]
  F --> G[Shared inbox sender]
  G --> H[Find workspace domain and check sending status]
  H --> I[Email provider]
  I --> J[Record results and bill sent emails]
  E --> K[Refresh statistics and check completion]
  J --> K
Loading

Reviews (1) · Last reviewed commit: "Send campaigns through a sender service ..." · Reviewed by Greptile

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant