I’m having trouble with my Mailgun email implementation in Python. The code executes without throwing any exceptions, but the emails never reach the recipient mailboxes. I’ve checked spam folders and waited several hours but nothing shows up.
Here’s my current setup:
import requests
def deliver_notification():
response = requests.post(
"https://api.mailgun.net/v3/sandbox47bc8d2398e154a7b945cc64e88f3c42.mailgun.org/messages",
auth=("api", "YOUR_API_TOKEN"),
data={
"from": "Newsletter Bot <[email protected]>",
"to": ["[email protected]", "[email protected]"],
"subject": "Test Message",
"text": "This is a test email via Mailgun API!"
}
)
return response
Has anyone experienced similar delivery problems with Mailgun? What could be preventing the emails from being sent successfully?
check your api key first - make sure it’s not the test key or expired. mailgun sandbox has weird restrictions too, so you might need to verify the receiver emails before they’ll work. i had the same issue last month and it turned out my domain wasn’t verified properly in the mailgun settings.
You’re probably using Mailgun’s sandbox domain - that’s your problem. Sandbox domains only send emails to recipients you’ve manually added to your authorized list in the dashboard. If those email addresses aren’t on the list, Mailgun just drops the emails without telling you. I got burned by this exact issue when I started with Mailgun and wasted hours debugging it. Fix it by adding your test recipients in the Mailgun control panel (look for authorized recipients), or switch to a custom domain if you want to email anyone. Double-check your API response codes too - make sure the calls are actually working on Mailgun’s side.
Your code’s running fine, but Mailgun’s probably rejecting the emails upstream. I had the same issue - got 200 responses but no emails because my sending reputation got flagged. Check your Mailgun logs dashboard. They track every API call and show exactly what happened to each message. Look for bounce codes or rejection reasons. Also make sure your domain authentication’s set up right - you need SPF and DKIM records in DNS. Without proper validation, email providers will drop Mailgun messages even when the API call works.