Bounce-Parser β lightweight Go library for detecting and parsing email bounce notifications (hard and soft).
Supports extracting failed recipient address (Mailbox) from multiple email formats used by Gmail, Outlook, Yahoo, Exchange, Postfix, SendGrid, SES, etc.
- Detect Hard bounce (permanent delivery failure)
- Detect Soft bounce (temporary delivery failure)
- Extract Mailbox (failed recipient) from:
X-Failed-Recipientsheadermessage/delivery-statuspart (Final-Recipient,Original-Recipient)message/rfc822part (Toheader of original message)
- Compatible with Gmail, Outlook, Yahoo, Postfix, Exchange, SendGrid, SES bounce formats
- Minimal dependencies β built on top of emersion/go-message
go get github.com/sarff/bounce-parserSee the example folder
Parse() returns a BounceInfo struct:
type BounceInfo struct {
Type BounceType // hard, soft, none
Reason string // human-readable reason
Subject string // original subject
Mailbox string // failed recipient address
}Undelivered MailMail Delivery FailedDelivery Status Notification (Failure)Failure NoticeUndeliverable:Your message wasn't delivered
550,553,User unknown,No such user,Mailbox does not existAddress not found,Recipient address rejected,Invalid recipient
Mailbox full,Quota exceeded,Temporarily deferredGreylisted,Server busy,Connection timed out
- Parse Hard/Soft bounce (basic patterns)
- Extract
Mailboxfrom:-
X-Failed-Recipientsheader -
Final-Recipient/Original-Recipientinmessage/delivery-status -
Toheader inmessage/rfc822
-
-
BounceInfostruct withType,Reason,Subject,Mailbox
- Write unit tests for
Parse()with:- Hard bounce detection by subject
- Hard bounce detection by body
- Soft bounce detection by body
- Mailbox extraction from
X-Failed-Recipients - Mailbox extraction from
Final-Recipient/Original-Recipient - Mailbox extraction from
Toinmessage/rfc822
- Add table-driven tests for various providers
- Add golden files for sample DSN messages
- Gmail (X-Failed-Recipients, Final-Recipient)
- Outlook / Exchange (Original-Recipient, Undeliverable subjects)
- Yahoo Mail (Final-Recipient, localized subjects)
- ProtonMail (check DSN structure β often RFC822 + localized)
- iCloud / Apple Mail (Apple DSN format)
- Zoho Mail (Final-Recipient and policy-based rejections)
- Postfix (typical
Undelivered Mail Returned to Sender) - Exim (Final-Recipient in delivery-status, no X-Failed-Recipients)
- SendGrid (Custom DSN formats + X-Failed-Recipients)
- Amazon SES (delivery-status only, no X-Failed-Recipients)
- Mailgun (Custom DSN JSON β check MIME fallback)
- Fastmail (Final-Recipient + localized bounce messages)
- Add language detection for localized subjects (RU, FR, DE, ES)
- Expand bounce keyword patterns for additional languages
- Implement performance benchmarks (large mailbox scanning)
- Add CI/CD pipeline with automated tests
- Add examples for common providers in
examples/
Thank you for considering contributing to Bounce-Parser!
We welcome bug reports, feature requests, test cases, and pull requests for improving bounce detection and mailbox extraction.
git clone https://github.com/<your-username>/bounce-parser.git
cd bounce-parsergit checkout -b feature/my-improvement- Add or update patterns for Hard/Soft bounce detection.
- Add mailbox extraction logic for new email providers.
- Improve parsing for
X-Failed-Recipients,Final-Recipient,Original-Recipient, ormessage/rfc822.
- Add table-driven tests in
parser_test.go. - Add sample
.emltest files for new providers (in/testdata). - Ensure all tests pass:
go test ./...Use Conventional Commits for commit messages:
feat(parser): add ProtonMail DSN mailbox extraction
fix(parser): correct Yahoo subject pattern
test(parser): add Amazon SES bounce examplePush your branch:
git push origin feature/my-improvement- Go to the main repository
- Open a Pull Request to
main - Provide a clear description of your changes and testing results
bounceparser/
parser.go # Main parsing logic
patterns.go # Subject/Body bounce patterns
mailbox.go # Mailbox extraction logic
types.go # Types and constants
parser_test.go # Unit tests
/examples # Usage examples
/testdata # Sample .eml files for testing
When adding a new provider:
- Add
.emltest message to/testdata - Add pattern(s) to
patterns.go - Add test case to
parser_test.go
- Follow idiomatic Go
- Use
go fmtbefore committing - Keep patterns lowercased for case-insensitive matching
Thank you for contributing! π
Your improvements make Bounce-Parser more reliable across different providers.
MIT License β see LICENSE