# How does Email-to-Case transform customer email correspondence into structured support cases?

**Topic:** Service Cloud · **Difficulty:** Medium · **Tags:** Service Cloud, Email-to-Case, Case Channels

Read it on the site: https://www.forcechallenges.com/interview-questions/how-does-email-to-case-transform-customer-email-correspondence-into-structured-support-cases

## Answer

**Basics:** Customers prefer emailing support@company.com. Email-to-Case gives each support mailbox a Salesforce routing address; every email creates a case (or updates an existing one if it is a reply), maps the sender to a Contact, and keeps the conversation inside the case so nobody works from a shared inbox.

**How it works:** Setup > Email-to-Case > enable; create Routing Addresses (name, email address, case priority, origin, owner or queue, record type, task options). Salesforce verifies the address and generates a unique Email Services address; you forward your mailbox to it. An inbound message creates a Case (Origin = Email), an `EmailMessage` (with `Incoming = true`), and saves attachments as Files or Attachments on the message. Agents reply from the Case Feed email action; replies are threaded using a thread ID or email headers. Assignment rules, auto-response rules and Flows then fire as normal.

**Advanced / deep dive:** Two variants: On-Demand Email-to-Case (cloud, recommended) and the legacy Email-to-Case Agent (installed behind your firewall). Reply threading can use the thread ID token in the subject or body and the email headers (Message-ID, References); header-based threading is more resilient. Use Flow or an Apex trigger on `EmailMessage` (after insert, where `Incoming = true`) for classification, auto-tagging or deflection. Limits exist on email size and daily volume (verify current values in the docs). Protect against spam and loops with auto-response rules, sender filtering, and "do not reply to auto-replies" logic. Use Enhanced Email so messages are stored as Salesforce records and can be related to other objects.

**Code / config example:**
```apex
// Trigger handler idea: tag new email-origin cases by keyword (bulk-safe)
public static void tagCases(List<EmailMessage> newMsgs) {
  Map<Id, String> subjByCase = new Map<Id, String>();
  for (EmailMessage m : newMsgs) {
    if (m.Incoming && m.ParentId != null && m.ParentId.getSObjectType() == Case.SObjectType) {
      subjByCase.put(m.ParentId, m.Subject);
    }
  }
  List<Case> toUpdate = new List<Case>();
  for (Id cid : subjByCase.keySet()) {
    if (String.isNotBlank(subjByCase.get(cid)) && subjByCase.get(cid).containsIgnoreCase('refund')) {
      toUpdate.add(new Case(Id = cid, Reason = 'Billing'));
    }
  }
  if (!toUpdate.isEmpty()) update toUpdate;
}
```

**Hidden gotchas & must-remember points:**
- A routing address must be verified before it works.
- Email Services-style size limits apply to message and attachments; large attachments can be rejected.
- Unmatched or duplicate sender emails leave Contact blank.
- Sandbox refreshes change generated addresses and thread IDs.
- Case creation happens before your trigger logic, so assignment rules may use default values.
- Spam and out-of-office replies can create cases or loops without filters.

**Best practice:** Use On-Demand Email-to-Case with header threading, and handle spam, auto-replies and attachments explicitly.

---
Source: ForceChallenges · last updated 2026-11-02
