By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,966 Members | 812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,966 IT Pros & Developers. It's quick & easy.

sending email using asp.net with C#

P: 15
hi,
In my application i am using smtp server for sending mails
i rote the host name,port in the web.config file like this
<configuration>
<configSections>
<sectionGroup name ="System.net" >
<section name="authenticationModules" type="System.Net.Configuration.NetAuthenticationMo duleHandler"></section>
</sectionGroup>
</configSections>
<system.net>
<mailSettings>
<smtp>
<network host ="mail.s2tech.net" userName ="Bhargavii@s2.net" password="BHaru" port ="25"/>
</smtp>
</mailSettings>
</system.net>


and i am retriving the values from the web.config to my .net application but i am getting an error for retriving the values..........


try
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpC ontext.Current.Request.ApplicationPath);
MailSettingsSectionGroup settings = new MailSettingsSectionGroup();
settings = (MailSettingsSectionGroup)config.GetSectionGroup(" System.net"); // here i am getting the eror
NetworkCredential credentials = new NetworkCredential();

credentials.UserName = settings.Smtp.Network.UserName;
credentials.Password = settings.Smtp.Network.Password;

smtpClient.Host = settings.Smtp.Network.Host;
smtpClient.Credentials = credentials;


message.From = new MailAddress(txtfrom.Text);
message.To.Add(txtto.Text);
message.Subject = txtsubject.Text;
message.IsBodyHtml = false;
message.Body = txtmessage.Text;

smtpClient.Send(message);


}
catch (Exception ex)
{
Response.Write(ex.Message);
}

i am getting the error at settings statement

settings = (MailSettingsSectionGroup)config.GetSectionGroup(" System.net");


please help me..........
Sep 26 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.