Reputation: 2352
Is it possible to address a mailmessage to a 'name' instead of an 'e-mailaddress'.
Something like this:
MailMessage mmsg = new MailMessage();
mmsg.To.Add("Winfrey");
instead of:
MailMessage mmsg = new MailMessage();
mmsg.To.Add(new MailAddress("[email protected]"));
Is it possible to add something in the 'To' part without the '@' and domain? And if so, how?
Upvotes: 0
Views: 645
Reputation: 317
The MailMessage class does not provide this. From where should this class know, which mail address is behind 'Winfrey'?
The only way is to create a simple address book.
Then you can write this
mmsg.To.Add(_addressBook["Winfrey"]);
_addressBook is a Dictionary here.
Dictionary<string, string> _addressBook = new Dictionary<string,string>();
Does this help?
Upvotes: 4
Reputation: 337
System.Net.Mail
doesn't validate the email that you are sending to. MailMessage.To
only accepts email address. See this!
Upvotes: 1
Reputation: 7465
If you are looking to see the sender's name on the e-mail that the other user receives:
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]", "winfrey" );
It'll display the name Winfrey.
Upvotes: 1