mail-inbound
Messagingtogo inbound email — parse & route incoming mail (SendGrid/Mailgun webhooks + RFC822)
togo install togo-framework/mail-inboundInstall
togo install togo-framework/mail-inboundThe 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.
Usage
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.
Webhooks
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).
Configuration
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.
<div align="center"> <h3>Premium sponsors</h3> <p> <a href="https://id8media.com"><strong>ID8 Media</strong></a> · <a href="https://one-studio.co"><strong>One Studio</strong></a> </p> <p><sub>Support togo — <a href="https://github.com/sponsors/fadymondy">become a sponsor</a>.</sub></p> </div>