For my latest venture, MyFamilio, I needed to know if a user’s Email address is a Gmail one so that I could show the user his/her contacts from Gmail.
Figuring out if the user is on Gmail is usually easy – the Email ends with @gmail.com. But what happens for all of those Google Apps for Your domain (like my own, which uses the @sandler.co.il domain) ?
Well, you can easily detect that by running a DNS query on the MX record.
I wrote a small function in Python which uses dnspyhon to do just that, determine if an Email address is hosted on Gmail or not.