Email Pipeline

How emails become tickets and conversations in GoPimi.

Overview

GoPimi's email pipeline connects your email addresses to tickets and conversations. Inbound emails are received via Mailgun webhooks, processed in background jobs, and routed based on your email's purpose setting. Outbound emails (replies) are sent through Mailgun with proper threading headers.

Email Purpose

Each workspace email has a purpose field that determines how inbound messages are routed:

PurposeUser Assigned?Inbound RoutingUse Case
ticketNoCreates or threads into ticketsCustomer support, issue tracking
inboxNoCreates or threads into shared conversationsShared inbox, visible to all workspace members
inboxYesCreates or threads into personal conversationsPersonal inbox, visible only to the assigned user

When a workspace email has a user assigned (user_id is set), inbound emails create personal conversations with owner_id set to that user. The owner is automatically assigned as agent. Notifications go only to the owner. When no user is assigned, conversations are shared and visible to all workspace members.

Inbound Email Flow

When an email arrives at one of your configured addresses:

  1. Mailgun webhook delivers the raw payload to GoPimi
  2. Raw JSON stored in storage/mailgun-incoming/ for debugging
  3. Background job picks up the email from the Redis queue
  4. Forwarding resolution — if the recipient is a forwarding address, resolves to the parent workspace email and extracts the real sender from the From header
  5. Purpose-based routing:
    • Threading first: If In-Reply-To header matches an existing message, routes to that ticket or conversation
    • Fresh email: Routes by the email's purpose — ticket creates a new ticket, inbox creates a new conversation
  6. Contact matching — sender is matched to an existing contact or a new one is created
  7. CC tracking — To and CC recipients stored on the message
  8. Attachments — files downloaded from Mailgun and stored as attachment records (up to 25 MB)

Outbound Email Flow

When an agent replies from the dashboard:

  1. Reply is saved as a message on the ticket or conversation
  2. A background job sends the email via Mailgun API
  3. Proper email headers are set:
    • Message-Id — unique identifier for this message
    • In-Reply-To — references the last inbound message
    • References — full thread chain
  4. File attachments and CC recipients from the message are included

Sending Email Resolution

For tickets, the sending email is resolved in order:

  1. The message's sending_email field (if set)
  2. The ticket's workspace_email
  3. First active sendable email in the workspace (can_send=true)

For conversations, agents can pick the "from" email when replying. The default is the last inbound message's to_email if it's sendable.

Email Setup Options

Platform Email

Use a GoPimi-provided address on the gopimi.com domain. No setup required — works immediately for both sending and receiving.

Custom Domain — Forwarding

Keep your existing email provider and forward messages to GoPimi. Configure your email provider to forward to the GoPimi forwarding address, then verify with a code or DNS record.

Custom Domain — MX Records

Point your domain's MX records to Mailgun for direct inbound delivery. Requires domain verification and DKIM setup for outbound.

Smart To-Header Resolution

When using a single forwarding address for multiple workspace emails, GoPimi matches the To header against all receivable workspace emails in the same workspace. This allows one forwarding rule to handle emails for multiple addresses.

Frequently Asked Questions

Can I use my own email domain without changing MX records?

Yes. Add a forwarding address to any workspace email, then configure your email provider to forward support mail to that address. No MX changes required.

How does GoPimi thread email replies?

Via Message-ID and In-Reply-To headers. Outbound replies include both so inbound replies are matched back to the original ticket or conversation.

What happens to attachments on inbound email?

They are downloaded from Mailgun and stored as Attachment records on the message. CID-referenced inline images are hidden from the body and exposed through the attachment system.

Which email providers does GoPimi support for inbound mail?

Mailgun is the only inbound provider today. The pipeline is architected so other providers can be added without touching upstream services.

What happens to mail sent to an unrecognized address?

If the recipient is not a known workspace email, the payload is moved to mailgun-skipped/ without creating a ticket or conversation. This prevents DMARC reports and misdirected mail from crashing the pipeline.

Related