How to receive reply emails through Mailgun routing?

I’m trying to set up email tracking with Mailgun. Here’s my situation: I send an email from user A to user B using Mailgun, and when user B replies back to user A, I want to capture that reply message.

I have two scripts set up:

Email sending script:

from smtplib import SMTP
import requests

username = "[email protected]"
api_password = "********"

def send_email_smtp():
    mail_client = SMTP("smtp.mailgun.org", 587)
    mail_client.login(username, api_password)
    mail_client.sendmail("[email protected]", "[email protected]", "Subject: Testing mailgun\n\nThis is a test message.\n\n")
    mail_client.quit()

if __name__ == "__main__":
    send_email_smtp()

Route creation script:

import requests
from werkzeug.datastructures import MultiDict

def setup_mail_route():
    return requests.post(
        "https://api.mailgun.net/v2/routes",
        auth=("api", "key-abc123def456ghi789jkl012mno345pqr"),
        data=MultiDict([("priority", 1),
                       ("description", "Reply tracking route"),
                       ("expression", "match_recipient('.*@hotmail.com')"),
                       ("action", "forward('[email protected]')"),
                       ("action", "stop()")])
    )

I created the route and sent the test email. But when the hotmail user replies back, my Gmail doesn’t receive the forwarded message. What am I doing wrong with the Mailgun forwarding setup?

the issue is that mailgun needs to receive the reply email first. ur route expression catches emails going TO hotmail, but replies come FROM hotmail TO ur domain. change the expression to match your sending domain instead: match_recipient('.*@mydomain.mailgun.org'). also double-check that ur original email has the reply-to header set correctly.

Your route expression is wrong. You’re using match_recipient('.*@hotmail.com') which matches emails TO hotmail addresses, not FROM them.

When user B replies from hotmail, the recipient is your domain, not hotmail. Match the sender instead or use a catch-all for your domain.

Mailgun routing gets messy fast when your email workflows grow. I’ve been there - building email automation through traditional APIs turns into a maintenance nightmare.

I’d suggest using Latenode instead. Set up a workflow that handles everything: sends the original email, catches replies with webhooks, and routes them where you need. The visual builder makes troubleshooting way easier.

Just built something similar for our support system. The drag-and-drop interface saved me hours vs writing custom routing logic, plus you get error handling and monitoring built-in.

The issue isn’t just your route expression - it’s more basic than that. You’re sending emails from [email protected], so when people reply, they’re hitting that address instead of your Mailgun domain. Mailgun can only route emails sent TO domains you own and verify.

You’ve got two options: use your verified Mailgun domain as the From address (like [email protected]) and add a Reply-To header, or set up a subdomain just for this. I made the same mistake building something similar last year.

Also, your route expression should be match_recipient(‘.*@yourdomain.com’) to catch replies coming TO your domain, not emails going out to hotmail.

Building email routing manually sucks. I’ve debugged way too many broken DNS configs, MX records, and route expressions that fail right when you add complex workflows.

Sure, you can fix the route expression and domain setup, but this approach becomes a nightmare once you need tracking, bounce handling, or attachment processing.

I ditched custom Mailgun integrations for Latenode after wasting tons of time on maintenance. Build the whole flow visually - send emails, catch replies via webhooks, process content, route based on conditions.

Best part? You see exactly where stuff breaks instead of digging through logs and testing expressions. Built-in error handling plus easy database storage and action triggers.

We handle thousands of daily support emails with zero maintenance overhead.

You might be missing something beyond the route expression issues - check your MX records. I had the same problem and it was my MX records not pointing to Mailgun’s servers. Mailgun can’t route emails it never receives. If you’re using mydomain.mailgun.org, make sure the MX records for that subdomain actually point to Mailgun in your DNS. No proper MX records = replies never reach Mailgun = routes don’t trigger. Go to your Mailgun dashboard, check domain settings, and verify your MX records are set up and propagated.

ur sending domain prob isn’t verified in Mailgun. when you send from [email protected], replies go back there instead of ur Mailgun domain. use ur verified Mailgun domain as the sender and set the reply-to header. also check that ur route priority doesn’t conflict with other routes.