Hi,
First write below code in web.config </system.weband before
</configuration>:
<system.net >
<mailSettings >
<smtp from="wh*@myhos t.com">
<network host="mail.myho st.net" userName="xxxxx " password="xxxx"/>
</smtp>
</mailSettings>
</system.net >
Then try this code:
Configuration configurationFi le =
WebConfiguratio nManager.OpenWe bConfiguration( "~\\Web.config" );
MailSettingsSec tionGroup mailSettings =
configurationFi le.GetSectionGr oup("system.net/mailSettings") as
MailSettingsSec tionGroup;
if (mailSettings != null)
{
int port = mailSettings.Sm tp.Network.Port ;
string host = mailSettings.Sm tp.Network.Host ;
string password = mailSettings.Sm tp.Network.Pass word;
string username = mailSettings.Sm tp.Network.User Name;
lblHost.Text = host;
lblUserName.Tex t = username;
lblPassword.Tex t = password;
}
Also include following namespaces:
using System.Configur ation;
using System.Web.Conf iguration;
using System.Net.Conf iguration;
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.
"David Thielen" wrote:
I've tried:
MailSettingsSec tionGroup mailConfig =
WebConfiguratio nManager.GetSec tion("system.ne t/mailSettings") as
MailSettingsSec tionGroup;
and:
Configuration configurationFi le =
WebConfiguratio nManager.OpenWe bConfiguration( "/Web.Config");
MailSettingsSec tionGroup mailConfig;
if (configurationF ile != null)
mailConfig = configurationFi le.GetSectionGr oup("system.net/mailSettings")
as MailSettingsSec tionGroup;
The first method returns null and the second returns an object but it does
not have the host or from properties set.
--
thanks - dave
david_at_windwa rd_dot_net
http://www.windwardreports.com
Cubicle Wars - http://www.windwardreports.com/film.htm