2026-11-30 · AgentStack Research Desk

How We Cut Cold Email Bounces Below 1% with Async Python (aiodns + Semaphore), n8n & Salesforge

#python#docker#tutorial#ai
How We Cut Cold Email Bounces Below 1% with Async Python (aiodns + Semaphore), n8n & Salesforge
Key Takeaway: Running an async Python pre-flight verifier (`aiodns` + `httpx` bounded by `asyncio.Semaphore`) before enrolling leads into Salesforge via n8n strips dead domains in milliseconds, prevents DNS rate-limiting, and keeps hard bounce rates below 1–2%.
Transparency note: Some links in this article are affiliate links. If you sign up through them, AgentStack may earn a commission at no extra cost to you. We only recommend tools we evaluate rigorously.

Quick Verdict (TL;DR)

Most B2B outbound pipelines fail before the first email copy is even read. Teams export 2,000 prospects from a scraper, upload the CSV straight into an email sequencer, hit a 12% hard-bounce spike, and spend the next month wondering why replies dropped to zero.

Below is the exact 2026 async Python + n8n + Salesforge pipeline we run to keep hard bounce rates below 1% while cutting third-party email verification spend by more than half.

Side-by-Side Comparison

Pipeline Stage Naive Manual Approach Automated Async Stack (2026) Monthly Cost Deliverability Risk
DNS / MX Pre-Filter None (upload raw CSV) Async Python (aiodns + Semaphore) in Docker $0 (runs on existing VPS) Eliminates dead domains instantly
Workflow & Catch-All Routing Manual spreadsheet cleanup Self-hosted n8n on Hostinger VPS (or Make) ~$6.49–$12/mo Enforces strict schema & suppression list
Multi-Inbox Sending & Warm-up Single Gmail / SES script Salesforge (Unlimited mailboxes + Warmforge + ESP matching) $48/mo (Pro) / $96/mo (Growth) Low (protected domain reputation)

Why Unbounded asyncio.gather() Breaks DNS Verification

When developers write their first async MX checker in Python, they call asyncio.gather(*[check(lead) for lead in leads]) on 5,000 leads at once. Two things immediately break:

  1. Local DNS resolver throttling: Firing 5,000 simultaneous UDP DNS queries trips upstream resolver rate limits and causes false-negative TimeoutError drops on valid corporate domains.
  2. Downstream API 429s: Slamming your CRM or Salesforge REST API concurrently without throttling triggers HTTP 429 rate limits.

Wrapping both steps in an asyncio.Semaphore keeps throughput fast (hundreds of leads per minute) while staying rock-solid under load.

Copy-Paste Async Python Verifier & Salesforge API Pusher

Install the lightweight dependencies (pip install aiodns httpx) and run this production-safe batch verifier inside Docker or alongside your self-hosted n8n container:

import asyncio
import os
import re
import aiodns
import httpx

SALESFORGE_API_KEY = os.environ["SALESFORGE_API_KEY"]
SALESFORGE_LEADS_URL = os.environ.get(
    "SALESFORGE_LEADS_URL", "https://api.salesforge.ai/public/v2/leads"
)
EMAIL_RE = re.compile(r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")
ROLE_PREFIXES = {"info", "support", "admin", "sales", "noreply", "no-reply", "billing"}


async def check_mx(
    resolver: aiodns.DNSResolver,
    domain: str,
    dns_sem: asyncio.Semaphore,
    mx_cache: dict[str, bool],
) -> bool:
    """Cached, semaphore-bounded async MX lookup."""
    if domain in mx_cache:
        return mx_cache[domain]
    async with dns_sem:
        try:
            records = await asyncio.wait_for(resolver.query(domain, "MX"), timeout=3.0)
            valid = len(records) > 0
        except (asyncio.TimeoutError, aiodns.error.DNSError):
            valid = False
    mx_cache[domain] = valid
    return valid


async def filter_and_push(
    leads: list[dict],
    dns_concurrency: int = 25,
    api_concurrency: int = 5,
) -> dict[str, int]:
    resolver = aiodns.DNSResolver()
    dns_sem = asyncio.Semaphore(dns_concurrency)
    api_sem = asyncio.Semaphore(api_concurrency)
    mx_cache: dict[str, bool] = {}

    async def _screen(lead: dict) -> dict | None:
        email = str(lead.get("email", "")).strip().lower()
        if not EMAIL_RE.match(email):
            return None
        local_part, domain = email.split("@", 1)
        if local_part in ROLE_PREFIXES:
            return None
        if not await check_mx(resolver, domain, dns_sem, mx_cache):
            return None
        return {**lead, "email": email, "mx_verified": True}

    screened = await asyncio.gather(*(_screen(l) for l in leads))
    valid_leads = [l for l in screened if l is not None]

    headers = {
        "Authorization": SALESFORGE_API_KEY,
        "Content-Type": "application/json",
    }
    pushed = 0

    async with httpx.AsyncClient(timeout=10.0) as client:
        async def _push(lead: dict) -> bool:
            async with api_sem:
                resp = await client.post(SALESFORGE_LEADS_URL, json=lead, headers=headers)
                return 200 <= resp.status_code < 300

        results = await asyncio.gather(*(_push(l) for l in valid_leads), return_exceptions=True)
        pushed = sum(1 for r in results if r is True)

    return {
        "input": len(leads),
        "mx_valid": len(valid_leads),
        "dropped_pre_flight": len(leads) - len(valid_leads),
        "pushed_to_salesforge": pushed,
    }

Notice mx_cache: dict[str, bool]: when enriching multiple contacts from the same target company, caching the domain's MX result cuts DNS queries by 40%–70%.

Wiring the 4-Node n8n Orchestration Flow

Host this script as a tiny FastAPI microservice on the same Docker network as your self-hosted n8n instance (running on a ~$8.79/mo Hostinger VPS KVM 2):

  1. Trigger: n8n Schedule or Webhook ingests newly enriched leads from Apollo/Apify.
  2. Pre-Flight Filter (HTTP Request): Sends the batch to your async Python MX verifier (http://lead-verifier:8000/verify), dropping dead domains and role addresses for $0.
  3. Deep SMTP / Catch-All Gate (IF Node): Run paid validation credits (included in Salesforge Pro/Growth) only on the MX-valid survivors—and tag Catch-All domains separately so you only send to them from your healthiest warmed mailboxes.
  4. Sequence Enrollment & Bounce Webhook: Enroll clean leads into Salesforge and listen to email_bounced / unsubscribed webhooks back in n8n (or Make) to maintain a permanent suppression table.

Who Should Choose What?

Tool Starting Price Best For Official Link
Salesforge $48/mo Multi-inbox AI cold email personalization and deliverability infrastructure Explore Salesforge
n8n Cloud Self-hosted Free / €20/mo Cloud Developers building custom LangChain & AI agent pipelines with full code control Start with n8n
Hostinger VPS $4.99/mo Low-cost KVM VPS for self-hosting n8n, Ollama, and autonomous AI agent workers Get Hostinger VPS
Make (formerly Integromat) Free / $9/mo Visual multi-step AI workflows with lower cost per operation than Zapier Try Make Free

Frequently Asked Questions

Is DNS MX record checking alone enough to stop cold email bounces?

No. MX verification is a fast, free pre-flight filter that strips dead domains and typos before you spend verification credits, but you should still run SMTP/catch-all verification (such as Salesforge's built-in validation credits) on the surviving leads to keep hard bounces below 1–2%.

Why should I use asyncio.Semaphore for Python DNS MX lookups?

Running thousands of unbounded concurrent DNS queries triggers upstream resolver rate limits and causes false timeouts on valid domains. Bounding lookups with asyncio.Semaphore(25) and caching results per domain keeps verification fast and accurate.

How do I handle Catch-All domains in a B2B outbound pipeline?

Flag Catch-All domains during verification rather than mixing them blindly into primary campaigns. Route them at low daily volume only through well-warmed secondary mailboxes with strict bounce webhook monitoring.

Can I run the Python verifier and n8n on the same VPS?

Yes. Packaging the async Python verifier as a lightweight FastAPI container inside the same Docker Compose network as n8n on a 2 vCPU / 8 GB RAM KVM VPS keeps latency under 2 milliseconds and total hosting under $10/month.