Is there a comprehensive way to test if two email addresses are equal? I know that I can universally LOWER both. But there are some other rules that differ from server to server. For example "[email protected]", "[email protected]", and "[email protected]" are all equivalent for gmail. But I don't think this is true in all cases. So given two email addresses I need to ensure they are equivalent. Currently my code does not consider "[email protected]" and "[email protected]" to be the same. I can start special casing something like "gmail" so they are but I was hoping there is a better approach.
Gmail only really has two rules for customization
.
) are ignored. This is easily overcome with a regex for gmail addresses.+
is ignored. Again. a regex will fix this for gmail addresses.The biggest challenge as I see it is that Google hosts thousands of cloud based domains that do not end in googlemail.com
or gmail.com
. Your only way to recognize these would be to do a DNS lookup and see what MX record the domain points to. Here's a python example that works:
http://eran.sandler.co.il/2011/07/17/determine-if-an-email-address-is-gmail-or-hosted-gmail-google-apps-for-your-domain/
You could do the same in any other language. Look at the 'MX' record for gmail or googlemail.
For any non-google domains, you can do a lowercase string compare.
A part from a custom coded set of rules for given email providers (e.g gmail for your example) I don't think there is any other way...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With