# Email & Campaigns Email is a product surface here, not just transactional plumbing. The platform runs **bulk marketing campaigns**, tracks how they perform, and protects sender reputation — all on top of AWS SES. ## Transactional email Fifteen mailers cover the lifecycle of the store — orders, OTPs, wishlists, flash sales, gift cards, payouts, vendor applications, and more. They share an `ApplicationMailer` base, render HTML-only emails, and are always delivered via `deliver_later` so a slow mail provider never blocks a web request. ## Marketing campaigns `EmailCampaign` drives bulk sends: - **Audience segmentation** — `CampaignAudienceService` builds the recipient list from user segments rather than blasting everyone. - **Block-based composition** — `CampaignBlockRenderer` assembles a campaign from content blocks; `CampaignHtmlSanitizer` keeps the output safe. - **Delivery** — `SendEmailCampaignJob` fans the send out across background workers, throttled by `EmailSendRateLimiter` to stay within SES limits. ## Tracking Every campaign send is measured: - **Open tracking** — a tracking pixel, with `EmailOpenClassifier` distinguishing genuine opens from prefetch noise. - **Click tracking** — `CampaignLinkRewriter` rewrites links so clicks are recorded as `email_campaign_link_click` rows. - **Attribution** — `CampaignAttributionService` ties downstream conversions back to the campaign that drove them. ## Protecting deliverability Sending bulk mail badly gets a domain blocklisted. The platform guards against that: - **Bounce & complaint handling** — `email_bounces` and `email_complaints` capture SES feedback. - **Suppression** — `EmailSuppressionService` ensures addresses that bounced or complained are never mailed again. - **Newsletters** — `NewsletterSubscription` supports double-opt-in and tokenised one-click unsubscribe. ## Re-engagement Email also closes the loop on shopping behaviour: abandoned-cart recovery, abandoned-wishlist reminders, price-drop alerts, and restock notifications all run as scheduled background jobs. ## Key files | Concern | Files | |---------|-------| | Models | `EmailCampaign`, `EmailCampaignRecipient`, `EmailCampaignLinkClick`, `EmailBounce`, `EmailComplaint`, `NewsletterSubscription` | | Services | `CampaignAudienceService`, `CampaignBlockRenderer`, `CampaignLinkRewriter`, `CampaignAttributionService`, `EmailSuppressionService`, `EmailSendRateLimiter` | | Jobs | `SendEmailCampaignJob`, `EmailOpenClassifier` |