Skip to content

Add automatic bounce polling for Google and custom SMTP/IMAP mailboxes#239

Open
ramyacm23 wants to merge 4 commits into
Kuldeeep18:mainfrom
ramyacm23:codex/imap-bounce-parser
Open

Add automatic bounce polling for Google and custom SMTP/IMAP mailboxes#239
ramyacm23 wants to merge 4 commits into
Kuldeeep18:mainfrom
ramyacm23:codex/imap-bounce-parser

Conversation

@ramyacm23

Copy link
Copy Markdown
Contributor

Summary

Closes #211

This PR adds automatic bounce detection for connected mailboxes.

Previously, bounce handling relied mainly on webhook events, which meant users sending through custom mailbox setups did not always get bounce updates. This change adds periodic mailbox polling so unread bounce notifications are parsed automatically and the matching campaign lead is marked as BOUNCED.

What Changed

  • Added a periodic Celery task to scan connected inboxes for unread bounce messages
  • Added bounce parsing logic to extract failed recipient addresses from mailbox messages
  • Updated campaign lead handling so matched leads are marked as BOUNCED and removed from further sequence execution
  • Marked processed bounce emails as read to avoid duplicate processing
  • Added support for custom SMTP/IMAP mailbox accounts in addition to existing Google-connected accounts
  • Added backend endpoints and settings UI support to create/remove custom mailbox accounts
  • Kept webhook bounce handling aligned with the same shared bounce-marking logic

Files Updated

  • backend/campaigns/tasks.py
  • backend/campaigns/gmail_service.py
  • backend/campaigns/mailbox_service.py
  • backend/campaigns/models.py
  • backend/campaigns/google_auth_views.py
  • backend/campaigns/views.py
  • backend/campaigns/tests.py
  • backend/backend/settings.py
  • backend/backend/urls.py
  • frontend/settings.html
  • backend/campaigns/migrations/0009_connectedemailaccount_custom_mailbox_fields.py

Why This Fix

This ensures bounce tracking works not only for webhook-based flows, but also for users who send through connected inboxes and custom SMTP/IMAP servers, improving automation and campaign hygiene.

Testing

Ran:

python manage.py test campaigns
python manage.py makemigrations --check --dry-run campaigns
Both completed successfully.

Notes
Google-connected mailbox polling remains supported
Custom mailbox support now includes:
SMTP sending
IMAP bounce polling
A production smoke test with a real custom mailbox is still recommended after deployment

@ramyacm23

Copy link
Copy Markdown
Contributor Author

@Kuldeeep18 , check with the pr

@Kuldeeep18 Kuldeeep18 added gssoc:approved GSSoC 2026 approved base points (+50 pts) level:advanced Difficulty: Advanced (+55 pts) type:feature Type: Feature (+10 pts) labels Jun 13, 2026
@Kuldeeep18 Kuldeeep18 force-pushed the codex/imap-bounce-parser branch from 932e2ef to fc6f1b3 Compare June 13, 2026 09:12
@Kuldeeep18

Copy link
Copy Markdown
Owner

Hi @ramyacm23! Thank you for the contribution. There are currently merge conflicts in backend/campaigns/tests.py. Please resolve the conflicts so that we can merge your PR.

@ramyacm23

Copy link
Copy Markdown
Contributor Author

@Kuldeeep18 , working on the conflicts. will raise a pr shortly.

@ramyacm23

Copy link
Copy Markdown
Contributor Author

@Kuldeeep18 , kindly check with the pr

@Kuldeeep18

Copy link
Copy Markdown
Owner

🚀 PR Guidelines — Read Before Raising a PR

Hey contributors 👋

I’m LeadOrbit's Bot, and I’ll review every PR before it gets merged.

✅ Your PR will only be merged if:

  • The code works correctly and u star the repo
  • There are no unnecessary changes
  • Issues pointed out by CodeRabbit are fixed
  • The PR follows clean coding practices
  • The project structure is maintained

❌ PRs that may be rejected:

  • Copy-paste or AI spam code
  • Unrelated changes
  • Low-quality README edits just for contribution count
  • Ignoring review comments
  • Broken builds or failing checks

Before submitting:

  1. Run and test your code properly
  2. Resolve all CodeRabbit suggestions
  3. Keep your PR focused and clean

And if you find the project useful, consider ⭐ starring the repository — it helps the project grow and motivates further development.

Quality contributions > PR count.

@ramyacm23

Copy link
Copy Markdown
Contributor Author

@Kuldeeep18 , as its advanced the changes are quite complex . if the changes are made manually it results in merge conflicts, i will rise a pr shortly .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC 2026 approved base points (+50 pts) level:advanced Difficulty: Advanced (+55 pts) type:feature Type: Feature (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LO-032 [Hard]: Automatic IMAP Email Bounce Parser

2 participants