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:
| Purpose | User Assigned? | Inbound Routing | Use Case |
|---|---|---|---|
ticket | No | Creates or threads into tickets | Customer support, issue tracking |
inbox | No | Creates or threads into shared conversations | Shared inbox, visible to all workspace members |
inbox | Yes | Creates or threads into personal conversations | Personal 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:
- Mailgun webhook delivers the raw payload to GoPimi
- Raw JSON stored in
storage/mailgun-incoming/for debugging - Background job picks up the email from the Redis queue
- Forwarding resolution — if the recipient is a forwarding address, resolves to the parent workspace email and extracts the real sender from the
Fromheader - Purpose-based routing:
- Threading first: If
In-Reply-Toheader matches an existing message, routes to that ticket or conversation - Fresh email: Routes by the email's purpose —
ticketcreates a new ticket,inboxcreates a new conversation
- Threading first: If
- Contact matching — sender is matched to an existing contact or a new one is created
- CC tracking — To and CC recipients stored on the message
- Attachments — files downloaded from Mailgun and stored as attachment records (up to 25 MB)
Outbound Email Flow
When an agent replies from the dashboard:
- Reply is saved as a message on the ticket or conversation
- A background job sends the email via Mailgun API
- Proper email headers are set:
Message-Id— unique identifier for this messageIn-Reply-To— references the last inbound messageReferences— full thread chain
- File attachments and CC recipients from the message are included
Sending Email Resolution
For tickets, the sending email is resolved in order:
- The message's
sending_emailfield (if set) - The ticket's
workspace_email - 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
- Getting Started — Set up your first email address
- Webhooks — Get notified when tickets or conversations are created
- API Reference — Email and ticket endpoints