Why there is "from" attribute of <smtp> element in <system.net><mailSettings>? How can i use it? As far as i see, i anyway have to specify From parameter for MailMessage class constructor. Can i use "from" attribute of <smtp> element for this in any natural way?
views:
46answers:
1
+2
A:
There is an overload of the MailMessage constructor that doesn't require any parameters. This will set the From property to the value in your .config file. See here for more information, particularly the "Remarks" section:
http://msdn.microsoft.com/en-us/library/ms144707.aspx
"From is set to the value in the network element for mailSettings Element (Network Settings), if it exists."
Tim
2010-08-18 06:52:12
Thanks, Tim. It makes sence. But i really did not get Remarks section meaning before your answer...
Konstantin
2010-08-18 07:31:59
If i do not specify "To" parameter for MailMessage condtructor, how do i do it later?
Konstantin
2010-08-18 07:39:04
Hi Konstantin, I agree this is also not obvious - you'd think you could set the "To" property to a string. Instead, you need to do this:mailMessage.To.Add(new MailAddress("[email protected]"));
Tim
2010-08-18 07:43:50
Ahhh. Shame on me! I was confused by read only nature of MailMessage.To property :-)Thanks, Tim. It really helps.
Konstantin
2010-08-18 07:54:31