Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

togo-framework/mail-inbound

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

togo

togo-framework/mail-inbound

marketplace pkg.go.dev MIT

Inbound email parsing & routing for togo — turn emails into application actions.

Install

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

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.


Premium sponsors

ID8 Media · One Studio

Support togo — become a sponsor.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /