Just found out today that System.Net.Mail.MailAddress (.Net 2.x/3.x) can't "eat its own dog food"; very frustrating.
Previously I decided that rather than waste my time trying to come up with a good email address validation routine, I'd use the one in MailAddress's constructor. (It has to go through there at some point anyhow.) I thought I got the additional bonus that it would actually normalize/fix some addresses it considered valid/OK/good enough. Unfortunately, I later found out that the constructor doesn't always like what it (itself) changes the address to.
MailAddress ma = new MailAddress("x y@z.com");
// ma.Address is "\"x y\"@z.com" at this point...
ma = new MailAddress(ma.Address); // this will throw an exception.
Now my validation routine has to send it through twice. This is to make sure that I never have to worry if subsequent code uses the "Address" value instead of the original.
Previously I decided that rather than waste my time trying to come up with a good email address validation routine, I'd use the one in MailAddress's constructor. (It has to go through there at some point anyhow.) I thought I got the additional bonus that it would actually normalize/fix some addresses it considered valid/OK/good enough. Unfortunately, I later found out that the constructor doesn't always like what it (itself) changes the address to.
MailAddress ma = new MailAddress("x y@z.com");
// ma.Address is "\"x y\"@z.com" at this point...
ma = new MailAddress(ma.Address); // this will throw an exception.
Now my validation routine has to send it through twice. This is to make sure that I never have to worry if subsequent code uses the "Address" value instead of the original.
Comments