Marketplace

mail-inbound

Messaging

togo inbound email — parse & route incoming mail (SendGrid/Mailgun webhooks + RFC822)

togo-framework
bash
togo install togo-framework/mail-inbound

Install

bash
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.

Usage

go
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/sendgridSendGrid Inbound Parse (multipart form)
POST/api/mail-inbound/mailgunMailgun routes (form fields)
POST/api/mail-inbound/rawraw RFC-822 message
GET/api/mail-inbound/receivedrecent inbound log
Rows per page
1–4 of 4
Page 1 of 1

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> &nbsp;·&nbsp; <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>