togo install togo-framework/mail-inbound
The togo answer to Laravel Mailbox / Rails Action Mailbox. Parse raw RFC-822 messages and provider webhooks (SendGrid Inbound Parse, Mailgun routes) into a normalized InboundMail, then route each message to a handler by recipient pattern or subject regex.
mb, _ := mailinbound.FromKernel(k) // Route support@ → open a ticket mb.Route(mailinbound.ToPrefix("support@"), func(ctx context.Context, m mailinbound.InboundMail) error { return tickets.Open(m.From, m.Subject, m.Text) }) // Route replies by plus-address token: reply+{token}@myapp.com mb.Route(mailinbound.ToContains("reply+"), func(ctx context.Context, m mailinbound.InboundMail) error { if token, ok := mailinbound.PlusToken(m); ok { return threads.Append(token, m.Text) } return nil }) // Match by subject mb.Route(mailinbound.SubjectMatch(`(?i)invoice`), billingHandler) // Anything unmatched mb.CatchAll(func(ctx context.Context, m mailinbound.InboundMail) error { return inbox.Store(m) })
InboundMail carries From, To, Cc, Subject, Text, HTML, MessageID, Headers, and decoded Attachments.
Point your provider's inbound parse at these endpoints (mounted automatically):
| Method | Path | Provider |
|---|---|---|
POST |
/api/mail-inbound/sendgrid |
SendGrid Inbound Parse (multipart form) |
POST |
/api/mail-inbound/mailgun |
Mailgun routes (form fields) |
POST |
/api/mail-inbound/raw |
raw RFC-822 message |
GET |
/api/mail-inbound/received |
recent inbound log |
You can also parse directly: mailinbound.ParseRFC822(raw), FromSendGrid(req), FromMailgun(req).
No required env. Set your DNS MX / provider inbound-parse to forward mail to the webhook URL, then register routes in your app. A bounded in-memory log keeps the most recent messages.