Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using email w/ Heroku and CNAME

Tags:

heroku

cname

I am in the process of setting up MX records on a HEROKU hosted app and am running into issues.

I have two CNAME's setup:

@ myapp.herokuapp.com
www myapp.herokuapp.com

Site works fine as setup above. I am now trying to add email support by adding Google Apps MX records.

@ ASPMX.L.GOOGLE.COM.  MX 10 1800  

--as well as four other MX fall backs--

Google Apps is saying it can't read the MX records. Is this because they are conflicting with the @ CNAME record? If so, should I drop that and used the "Naked Domain" method (Setup three A records instead). Heroku makes it sounds like this method is highly discouraged vs CNAMEs for "@" non WWW.

Thanks for the help!

like image 935
cman77 Avatar asked Jul 27 '12 18:07

cman77


3 Answers

I found the best way to do this is to use Google Apps "Naked Domain" 301 Redirect Feature as described in https://support.google.com/a/answer/2518373?hl=en

1) Go to Admin Console - Domains - Change Naked Redirect

2) Redirect to WWW.your_domain.com

3) You will setup 4 A-Records in your DNS pointing your your_domain.com to

  • 216.239.32.21
  • 216.239.34.21
  • 216.239.36.21
  • 216.239.38.21

Now, when somebody points to your_domain.com they get 301 redirected to WWW.your_domain.com This, btw is the same way gooogle.com behaves (301 redirect to www.google.com)

HT: http://smallchou.com/post/41388058201/heroku-and-root-aka-apex-or-naked-domains

like image 53
Leo Tulipan Avatar answered Oct 18 '22 07:10

Leo Tulipan


Apparently they conflict. From Heroku:

Hi, you can't have CNAME entries on the zone apex. 
You'll need to do the A records setup, or use a DNS provider that 
supports ALIAS/ANAME records (DNSimple, DNS Made Easy, Route 53).

Removing the @ CNAME and replacing it with A records seemed to work - within minutes Google picked up my MX records.

Final setup was a single WWW CNAME pointing to myapp.herokuapp.com. and three A records, each pointing to one of the Heroku listed IPs.

like image 35
cman77 Avatar answered Oct 18 '22 07:10

cman77


I was just struggling with something like this. When I switched to Heroku I added the CNAME to point my root domain (my_domain.com) to heroku and that link I guess forwards everything and kills your MX records for email, so the way I solved it was to instead point just my www subdomain to heroku via cname record (www.my_domain.com), and then I added a link forwarding my root domain (my_domain.com) to my subdomain (www.my_domain.com). Then my MX records worked again, but I had to wait a few hours for it to start working (luckily I gave up and went to bed and then in the morning realized it had worked). To point the root to the www subdomain, my domain name provider had a setting called pointers, and the options I selected were 'standard', 'URL' and 'www.my_domain.com'

Then to get SSL to work I had to add a redirect in the backend webserver code to redirect http to https, so I guess now if you type my_domain.com it redirects to www.my_domain.com and then redirects to https.my_domain.com, so kinda crazy but it works super fast so I guess it's good.

like image 2
Jesse Adamson Avatar answered Oct 18 '22 06:10

Jesse Adamson