1

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 testemail@test.com 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',["*test@test.com*"],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.

medmunds
  • 5,950
  • 3
  • 28
  • 51
Chris Wedgwood
  • 660
  • 6
  • 11
  • What are your anymail settings? – markwalker_ Apr 05 '19 at 11:50
  • If someone else comes across this be sure to check your MAILGUN_API_URL to have either `https://api.mailgun.net/v3` for Mailgun’s US service or `https://api.eu.mailgun.net/v3` for Mailgun’s European service – SamWanekeya Dec 24 '19 at 13:07

1 Answers1

3

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.")

medmunds
  • 5,950
  • 3
  • 28
  • 51
  • Thank you very much. It was indeed an issue with MAILGUN_SENDER_DOMAIN. Also thank you for improving the title..much more useful. Have a good weekend! – Chris Wedgwood Apr 05 '19 at 20:23