Should I use System.Net.Mail.MailAddress in my domain model, or just strings?

173 Views Asked by At

As covered well in this question, System.Uri is a good choice to reflect my intention for URIs. But what about for email addresses?

It seems not as clear-cut, because MailAddress has extra information in its DisplayName property that is not a great fit.

2

There are 2 best solutions below

0
On BEST ANSWER

You don't have to use the DisplayName if you don't want or need to. The MailAddress type ensures that an email address is well formed by throwing an exception in it's constructor otherwise. I would argue that it is worth using MailAddress over String for this reason and also because it communicates intent and adds little overhead.

0
On

System.Uri has a lot of useful functionality, but System.Net.Mail.MailAddress doesn't, so whether to use it is not a critical decision. FWIW, I have implemented it both ways (but in different places!) -- string and MailAddress.