I am trying to setup emails with my own website. Let's say the domain name is abc.com
.
The nameserver in use is digital ocean and I also have a gmail account linked to the same (say using contact@abc.com
).
While setting up things with mailgun, I used mg.abc.com
(as they said it would also let me email using the root domain). The verification step is done and I can send email using contact@mg.abc.com
.
However, trying to use the root domain (contact@abc.com
) gives the following error:
AnymailRequestsAPIError: Sending a message to me@gmail.com from contact@abc.com ESP API response 404: { "message": "Domain not found: abc.com" }
How do I resolve this issue?
Update 8/22/16: Anymail has been updated to take a new MAILGUN_SENDER_DOMAIN in settings.py. See version .5+ docs.
-- Original Answer You did not post your code for how you're sending your email, but you are probably trying to send using the simple send_mail() function:
from django.core.mail import send_mail send_mail("Subject", "text body", "contact@abc.com", ["to@example.com"],)
When you use this method, Anymail pulls the domain out of your From address and tries to use this with Mailgun. Since your From address (abc.com) doesn't include the subdomain mg., Mailgun is confused.
Instead, you need to send the email using the EmailMultiAlternatives
object and specify the Email Sender Domain like so:
from django.core.mail import EmailMultiAlternatives msg = EmailMultiAlternatives("Subject", "text body", "contact@abc.com", ["to@example.com"]) msg.esp_extra = {"sender_domain": "mg.abc.com"} msg.send()
Don't forget the brackets in your To field, as this needs to be a tuple or list even if you're only sending it to one recipient.
For more information, see Anymail docs on esp_extra.