Search code examples
ruby-on-railsemailmailgun

Can't send emails to custom domains (non-gmail/hotmail emails) using Mailgun


I am sending out confirmation (and other emails) when users sign up. The problem is that when I send to addresses that are not gmail or hotmail or any of the larger email services, it throws me an error in the email header.

{
  "severity": "permanent",
  "tags": [],
  "delivery-status": {
    "tls": false,
    "mx-host": "mxer.customdomain.com",
    "code": 553,
    "description": null,
    "session-seconds": 6.566637992858887,
    "message": "553 5.1.8 <[email protected]>... Domain of sender address [email protected] does not exist",
    "certificate-verified": false
  },
  "envelope": {
    "transport": "smtp",
    "sender": "[email protected]",
    "sending-ip": "123.45.678.900",
    "targets": "[email protected]"
  },
  "recipient-domain": "customdomain.com",
  "id": "AbCDeFGhiJk_lMn",
  "campaigns": [],
  "reason": "generic",
  "user-variables": {},
  "flags": {
    "is-routed": null,
    "is-authenticated": true,
    "is-system-test": false,
    "is-test-mode": false
  },
  "log-level": "error",
  "timestamp": 1456123374.411238,
  "message": {
    "headers": {
      "to": "First Last <[email protected]>",
      "message-id": "56caade72ed26_***********[email protected]",
      "from": "Team Accounts <[email protected]>",
      "subject": "Confirmation instructions"
    },
    "attachments": [],
    "recipients": [
      "[email protected]"
    ],
    "size": 1143
  },
  "recipient": "[email protected]",
  "event": "failed"
}

Did I set my headers wrongly or is there a configuration I need to set up before I can send emails to custom domains?


Solution

  • It seems that for some email services, it requires a valid "receive" MX record for your domain/subdomain (for Mailgun it was mg.mydomain.com) to verify the identity of the sender. I added the MX records

    10 mxa.mailgun.org
    10 mxb.mailgun.org
    

    for mg.mydomain.com and it seemed to have worked.