Title: Can I use Mailgun and SendGrid on same domain
Tags: php;wordpress;sendgrid;mailgun
Question: I have separate WordPress installs on the root domain, on 3 subdomains of that root domain and on some subdirectories. My partner set up SendGrid to send email notifications to subscribers from the WP installs and it is working well.

We recently installed a custom PHP script that integrates with Twilio on another subdomain of the root domain. The coder integrated this script with Mailgun to send password reset emails and Twilio call notifications to subscribers. We've set the subdomain for Mailgun functionality to be mg.ourdomain.com.  We understand that Mailgun functionality also extends to ourdomain.com   We have not yet verified the account (added MX records), pending confirmation that we can use both SendGrid and Mailgun on the same domain. 

In summary, SendGrid is being used with WP installs on ourdomain.com, subdomain1.ourdomain.com, subdomain2.ourdomain.com, subdomain3.ourdomain.com., ourdomain.com/subdirectory1. Mailgun would be used with PHP script on subdomain4.ourdomain.com  Note that for both the WP installs and the PHP script, we will not be receiving any emails, only sending them.

If we can use both SendGrid and Mailgun, is it simply a matter of adding MX records for each email service or is there something else we must do.?

Comment: You can use both for *outgoing* email (but you'll want to make sure you set up your SPF etc. records properly). You cannot use both for *inbound* email. Multiple MX records will mean some email goes to one and other email goes to the second (if same priority).


Here is another answer: You technically can, but you probably don't want to. I would encourage consolidating onto a single sending platform. It sounds like you had a developer hard-code Mailgun into something so you'll need his/her help (or another developer) to swap that out, but on the WordPress side you could easily switch Sendgrid to Mailgun by swapping out the plugin you're using. I personally use the Mailgun WordPress plugin on a dozen or so WordPress sites and it works great.

If you're married to using both, this is what it would look like.

Email DNS setup requires MX records, which point to the servers that will receive mail for your domain, and domain verification records like DKIM and SPF records, which tell email clients what servers to trust when they receive mail from your domain. Since you're probably using your domain for individual email accounts as well (e.g. via Google Apps) you don't want to change your MX records or your individual inboxes will stop receiving mail.

It is possible to set up more than one DKIM record and to create an SPF record that includes multiple sender entries... BUT you don't want your SPF record to get too crowded. The SPF specification includes a hard limit of 10 DNS lookups when email clients validate a message. That sounds like a lot, but consider each domain entry isn't a single lookup, it may be 2 or 3.

Here's an example: this SPF allows Google, Mailgun and Mailchimp to send email from my domain.

```v=spf1 include:_spf.google.com include:mailgun.org include:servers.mcsv.net ~all
```

If I wanted I could add in Sendgrid using something like this:

```v=spf1 include:_spf.google.com include:mailgun.org include:servers.mcsv.net include:sendgrid.net ~all
```

But that's getting dangerously close to the SPF lookup limit, if each of these happen to do 3 lookups I could start to have messages rejected.


Here is another answer: SendGrid Whitelabeling requires a dedicated Subdomain, due to the MX/CNAME records being controlled for Return-Path validation, Bounce returns, etc. But that's just a whitelabeled Domain, it doesn't have to be the same one as where you have the setup installed.

So, you could have any number of WordPress installs, all configured to use the same SendGrid account, and have a distinct whitelabel on that account, such as ```sg.domain.com```.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:12/19/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><wordpress><sendgrid><mailgun>', 'Title': 'Can I use Mailgun and SendGrid on same domain', 'ViewCount': 1021, 'id': 41231946, 'user_AboutMe': None, 'user_AccountId': 9883035.0, 'user_DisplayName': 'Genome', 'user_Reputation': 21.0, 'user_Views': 0.0, 'user_id': 7318489.0}}