I’m creating a function uses Google’s API to import contacts from a person’s gmail account. However I’m aware that many businesses sign up to Google in order to have a more professional domain name( eg. some_name@bislr.com) but still belongs to Gmail.
Is there a way to check for that?
Option 1
if you do a DNS lookup for the MX records on bislr.com, you get the following:
Anyone hosting their email Google Apps will have MX records very similar to these. You can do a MX lookup with any common DNS mechanism and test the MX records for Google’s most-recommended mail servers – aspmx.l.google.com, alt1.aspmx.l.google.com, and alt2.aspmx.l.google.com, or look for any/all of the servers in this list.
This won’t show you anyone who uses an external forwarding/filtering service but it will work for all of the common cases.
Option 2
You can connect to a mail server to verify if it will accept mail to a specific address. Using this, we can connect to asmpx.l.google.com and ask it whether an address is a valid Google Mail account.
If you connect to aspmx.l.google.com:25 and send this string (replace the email addresses as appropriate):
Google’s mail server will respond with a smtp status code, probably a line starting with something like
250 2.1.5 OKif it’s a valid address. This is a cleaner and far more reliable way than simply checking DNS records, and should work as long as you don’t get the checking IP blacklisted by using it to send actual spam to gmail.Here is a full walkthrough of the process.