I am running a django application running on docker and I am using django-anymail to send emails via mailgun.
When I go through for example a forgot my password process I am getting an error in django-anymail:
AnymailRequestsAPIError: Invalid JSON in Mailgun API response Sending a message to [email protected] from info@application.co.uk Mailgun API response 200 (OK): 'Mailgun Magnificent API' @ anymail/backends/base_requests.py in deserialize_json_response at line 106
I am able to re-create this error if I docker exec -it
onto the django container and run the following in a python manage.py shell
from django.core.mail import send_mail
customer_email = send_mail('Test','Test','info@*application*.co.uk',["*[email protected]*"],fail_silently=False)
If I run this after building and running my production.yml
docker locally it works and I get an email but if I run this on the container on my digital ocean droplet I receive an error.
Is there a configuration I am missing in order to get this working? I have another django application just running on a droplet(no docker) and it works fine with mailgun using the same setup.
The error "Mailgun Magnificent API" is most likely caused by a #
character in your MAILGUN_SENDER_DOMAIN. That often happens when you try to use line-end comments in a config file format that doesn't support them—like dotenv:
# .env
MAILGUN_SENDER_DOMAIN=mail.example.com # INVALID: dotenv doesn't allow comment here
If you upgrade to django-anymail v6.0, you'll get an improved error message that makes this more obvious.
(This answer covers other situations that can lead to "Mailgun Magnificent API.")