Search code examples
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": "[email protected]",
      "message-id": "[email protected]",
      "from": "[email protected]",
      "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": "[email protected]",
    "sending-ip": "209.61.151.224",
    "targets": "[email protected]"
  },
  "message": {
    "headers": {
      "to": "[email protected]",
      "message-id": "[email protected]",
      "from": "[email protected]",
      "subject": "Mail test !"
    },
    "attachments": [],
    "recipients": [
      "[email protected]"
    ],
    "size": 643
  },
  "recipient": "[email protected]",
  "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=['[email protected]',],
            from_email=settings.DEFAULT_FROM_EMAIL,
            fail_silently=False,
        )
        messages.success(request, 'Email correctement envoyé !')
    return redirect('rideshare_event_list')

Solution

  • Try using [email protected] as your from address instead of [email protected].

    I'm afraid I'm not sure whether it's possible to use [email protected] as the from address.