djangomailgunovhdjango-anymail

Django and Mailgun : 552 sorry, your envelope sender domain must exist (#5.7.1)


I'm trying to send mail using Django and Mailgun through the Anymail package and with an OVH server.

I'm currently receiving the 552 sorry, your envelope sender domain must exist (#5.7.1) error.

In this question/answer, it is suggested that I would need a "from" header, but the response I'm getting seems to show that the header is already included :

    "headers": {
      "to": "evenements@mydomain-longversion.org",
      "message-id": "20160915065953.15168.46300.4ABD80EB@mailgun.mydomain.fr",
      "from": "covoiturage@mydomain.fr",
      "subject": "Mail test !"
    },

Here is the full response, for reference :

{
  "severity": "permanent",
  "tags": [],
  "storage": {
    "url": "https://si.api.mailgun.net/v3/domains/mailgun.mydomain.fr/messages/eyJwIjpmYWxzZSwiayI6ImI5OGIyN2QzLTM2MmEtNGJjNi05ZWViLTRlMTA0NTVmYTIxMiIsInMiOiJlNmY5NzZhZTYwIiwiYyI6InNiaWFkIn0=",
    "key": "eyJwIjpmYWxzZSwiayI6ImI5OGIyN2QzLTM2MmEtNGJjNi05ZWViLTRlMTA0NTVmYTIxMiIsInMiOiJlNmY5NzZhZTYwIiwiYyI6InNiaWFkIn0="
  },
  "delivery-status": {
    "tls": false,
    "mx-host": "redirect.ovh.net",
    "attempt-no": 1,
    "description": null,
    "session-seconds": 0.9216420650482178,
    "code": 552,
    "message": "552 sorry, your envelope sender domain must exist (#5.7.1)",
    "certificate-verified": false
  },
  "recipient-domain": "mydomain-longversion.org",
  "event": "failed",
  "campaigns": [],
  "reason": "generic",
  "user-variables": {},
  "flags": {
    "is-routed": null,
    "is-authenticated": true,
    "is-system-test": false,
    "is-test-mode": false
  },
  "log-level": "error",
  "timestamp": 1473922798.282194,
  "envelope": {
    "transport": "smtp",
    "sender": "postmaster@mailgun.mydomain.fr",
    "sending-ip": "209.61.151.224",
    "targets": "evenements@mydomain-longversion.org"
  },
  "message": {
    "headers": {
      "to": "evenements@mydomain-longversion.org",
      "message-id": "20160915065953.15168.46300.4ABD80EB@mailgun.mydomain.fr",
      "from": "covoiturage@mydomain.fr",
      "subject": "Mail test !"
    },
    "attachments": [],
    "recipients": [
      "evenements@mydomain-longversion.org"
    ],
    "size": 643
  },
  "recipient": "evenements@mydomain-longversion.org",
  "id": "TfJKwpoZQq6bM-MW5sm6nA"
}

And here is my Django code :

def SendTestEmail(request):
    if request.user.is_staff and settings.DEBUG == True :
        send_mail(
            subject='Mail test !',
            message='''Bonjour {}, votre email a bien été envoyé.'''.format(request.user.get_full_name()),
            recipient_list=['evenements@mydomain-longversion.org',],
            from_email=settings.DEFAULT_FROM_EMAIL,
            fail_silently=False,
        )
        messages.success(request, 'Email correctement envoyé !')
    return redirect('rideshare_event_list')

Solution

  • Try using covoiturage@mailgun.mydomain.fr as your from address instead of covoiturage@mydomain.fr.

    I'm afraid I'm not sure whether it's possible to use covoiturage@mydomain.fr as the from address.