tags:

views:

65

answers:

1

Unfortunately my hMailServer can't send emails to Hotmail. How can I determine whether a given email address is Hotmail or not, to prevent the message from being lost.

Hotmail e-mails can be: * @live.com * @live.fr[pt][ru][etc] * @hotmail.com, * @live.com.jp * @msn.com * and many country TLD specific combinations involving MSN, Hotmail and Live.

It seems like it's impossible to use a regular expression to filter that.

Any ideas on how to detect whether an email addresses is in the Hotmail family of addresses?

+2  A: 

This will work:

function bool IsHotmailAddress(string email) {
    var r = new Regex(@"\@(live|hotmail)\.[a-z]{2,3}(\.[a-z]{2,3})?$", RegexOptions.IgnoreCase);
    return r.IsMatch(email);
}
BC
Indeed. I was too lazy to add the rest of it :P
NullUserException
this would give false positives for the rare sites like [email protected] or [email protected] which would not be hotmail addresses. You could fix this by changing the [a-z] matches to match any of the tld's ( (co|com|org|edu|net|jp|ca|...) but I think this is overkill and something you would have to add to over time.
BC
Thanks! I wish I was a RegEx guru too... I just don't get this stuff.
Alex
*@Alex* Try not to use too many things you just don't get; it makes for impossible-to-debug code. Instead, teach yourself! http://www.regular-expressions.info/reference.html is great.
Daniel Rasmussen
Thanks, I'll check it out.
Alex