adding smtpClient to web.config

G

Guest

Using VisualStudio 2005, asp.net 2.0:

What do I put in my Web.Config to avoid hard coding the: myserveraddress.com?

The following shows how I have hard coded it without having the value in the
we.config, and it works. However, I would like to place it in my web.config
file, and then just get the value from the web.config?

Can someone tell me what I need to add to the web.config

//send the message
System.Net.Mail.SmtpClient smtp = new
System.Net.Mail.SmtpClient("smtp.myserveraddress.com");
smtp.Send(mail);
 
G

Guest

The solution offered is more than I need.

Can someone simply provide a sample of the lines that I need to add to the
web.config for asp.net 2.0.
 
S

Swanand Mokashi

Add the <mailSettings> block in <system.net> block in the web.config file.
for e.g.
<system.net>
<mailSettings>
<smtp from="(e-mail address removed)">
<network host="127.0.0.1"
password="" userName="" />
</smtp>
</mailSettings>
</system.net>


--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
 
G

Guest

Yes, thank you.
Using the web.config setting, what change needs to be made to the following
code.

//send the message
 
S

Swanand Mokashi

Comment the first line where you are setting the smtpClient
and replace it by just

SmtpClient client = new SmtpClient();

System.Net.Mail reads SMTP configuration data out of the standard .NET
configuration system (so for ASP.NET applications you'd configure this in
your application's web.config file)

Check Scott Guthrie's post here :
http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx


--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,293
Latest member
Hue Tran

Latest Threads

Top