Question

My site allows logins with Google accounts and you can also invite your contacts from Gmail or Google Apps.

I'm trying to determine if the user invited has a google account or not. So far I check if the domain is gmail but for google apps account I cannot perform this kind of validation since the domain name can be anything.

Is it reliable to lookup the MX (Mail Exchanger) through dig command and see if the MX is a google server?

I can perform this validation in Java like this

Record[] records = new Lookup("example.com", Type.MX).run();
    for (int i = 0; i < records.length; i++) {
        MXRecord mx = (MXRecord) records[i];
        System.out.println("Host " + mx.getTarget() + " has preference "
                + mx.getPriority());
        if (mx.getTarget().toString().toLowerCase().endsWith("google.com.")
                || mx.getTarget().toString().toLowerCase().endsWith("googlemail.com.")) {
            System.out.println("is google!!!");
        }
    }

Is this method (Looking up the MX of the domain) reliable? Could this MX change?

Thanks

EDIT

So far I've found that google has the following MX ordered by priority

  • 0 aspmx.l.google.com.
  • 10 alt1.aspmx.l.google.com.
  • 20 alt2.aspmx.l.google.com.
  • 30 alt3.aspmx.l.google.com.
  • 40 alt4.aspmx.l.google.com.
  • 50 aspmx2.googlemail.com.
  • 60 aspmx3.googlemail.com.
  • 70 aspmx4.googlemail.com.
  • 80 aspmx5.googlemail.com.

So, from my perspective it is safe to say that if the MX ends with google.com. or googlemail.com. it's a Google Apps account. Is this reliable?

Was it helpful?

Solution

It could change but it's very unlikely since Google wouldn't gain anything from it.

I'm not a Google employee, so I can't give a guaranteed answer, but here's my understanding of the situation:

  1. Google won't ask existing clients to change their MX records because it's extra hassle for the client with no benefit to Google and would just make companies less likely to choose them.

  2. Google could always start asking new clients to use MX records pointing to non-Google top-level domains, but they probably won't. Google seems to be in love with serving as many of their services as possible from google.com subdomains. (In fact, it's a pain to properly block some kinds of Google ads and APIs because they're served from the same www.google.com subdomain used for things like Google Search.)

  3. Worst case scenario, you get a false negative. "Some" is still better than "none" even if it isn't "all".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top