473,804 Members | 3,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding smtpClient to web.config

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("sm tp.myserveraddr ess.com");
smtp.Send(mail) ;
Apr 20 '06 #1
6 10497
check my blog:
http://spaces.msn.com/sholliday/ 2/8/2006 entry

I wrote a very nice (if I do say so my self) for having lots of flexibility
with smtp server settings.

There is a 2.0 and 1.1 example.


"theWizard1 " <th********@dis cussions.micros oft.com> wrote in message
news:64******** *************** ***********@mic rosoft.com...
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("sm tp.myserveraddr ess.com");
smtp.Send(mail) ;

Apr 20 '06 #2
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.

"sloan" wrote:
check my blog:
http://spaces.msn.com/sholliday/ 2/8/2006 entry

I wrote a very nice (if I do say so my self) for having lots of flexibility
with smtp server settings.

There is a 2.0 and 1.1 example.


"theWizard1 " <th********@dis cussions.micros oft.com> wrote in message
news:64******** *************** ***********@mic rosoft.com...
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("sm tp.myserveraddr ess.com");
smtp.Send(mail) ;


Apr 20 '06 #3
Add the <mailSettings > block in <system.net> block in the web.config file.
for e.g.
<system.net>
<mailSettings >
<smtp from="fr**@test .com">
<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

"theWizard1 " <th********@dis cussions.micros oft.com> wrote in message
news:FD******** *************** ***********@mic rosoft.com...
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.

"sloan" wrote:
check my blog:
http://spaces.msn.com/sholliday/ 2/8/2006 entry

I wrote a very nice (if I do say so my self) for having lots of
flexibility
with smtp server settings.

There is a 2.0 and 1.1 example.


"theWizard1 " <th********@dis cussions.micros oft.com> wrote in message
news:64******** *************** ***********@mic rosoft.com...
> 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("sm tp.myserveraddr ess.com");
> smtp.Send(mail) ;


Apr 20 '06 #4
Yes, thank you.
Using the web.config setting, what change needs to be made to the following
code.

//send the message
> System.Net.Mail .SmtpClient smtp = new
> System.Net.Mail .SmtpClient("sm tp.myserveraddr ess.com");
> smtp.Send(mail) ;


"Swanand Mokashi" wrote:
Add the <mailSettings > block in <system.net> block in the web.config file.
for e.g.
<system.net>
<mailSettings >
<smtp from="fr**@test .com">
<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

"theWizard1 " <th********@dis cussions.micros oft.com> wrote in message
news:FD******** *************** ***********@mic rosoft.com...
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.

"sloan" wrote:
check my blog:
http://spaces.msn.com/sholliday/ 2/8/2006 entry

I wrote a very nice (if I do say so my self) for having lots of
flexibility
with smtp server settings.

There is a 2.0 and 1.1 example.


"theWizard1 " <th********@dis cussions.micros oft.com> wrote in message
news:64******** *************** ***********@mic rosoft.com...
> 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("sm tp.myserveraddr ess.com");
> smtp.Send(mail) ;


Apr 20 '06 #5
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/archi...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

"theWizard1 " <th********@dis cussions.micros oft.com> wrote in message
news:18******** *************** ***********@mic rosoft.com...
Yes, thank you.
Using the web.config setting, what change needs to be made to the
following
code.

//send the message
>> > System.Net.Mail .SmtpClient smtp = new
>> > System.Net.Mail .SmtpClient("sm tp.myserveraddr ess.com");
>> > smtp.Send(mail) ;

"Swanand Mokashi" wrote:
Add the <mailSettings > block in <system.net> block in the web.config
file.
for e.g.
<system.net>
<mailSettings >
<smtp from="fr**@test .com">
<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

"theWizard1 " <th********@dis cussions.micros oft.com> wrote in message
news:FD******** *************** ***********@mic rosoft.com...
> 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.
>
> "sloan" wrote:
>
>> check my blog:
>> http://spaces.msn.com/sholliday/ 2/8/2006 entry
>>
>> I wrote a very nice (if I do say so my self) for having lots of
>> flexibility
>> with smtp server settings.
>>
>> There is a 2.0 and 1.1 example.
>>
>>
>>
>>
>> "theWizard1 " <th********@dis cussions.micros oft.com> wrote in message
>> news:64******** *************** ***********@mic rosoft.com...
>> > 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("sm tp.myserveraddr ess.com");
>> > smtp.Send(mail) ;
>>
>>
>>


Apr 20 '06 #6
Thank you. It all works. You made it so simple.

"Swanand Mokashi" wrote:
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/archi...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

"theWizard1 " <th********@dis cussions.micros oft.com> wrote in message
news:18******** *************** ***********@mic rosoft.com...
Yes, thank you.
Using the web.config setting, what change needs to be made to the
following
code.

//send the message
>> > System.Net.Mail .SmtpClient smtp = new
>> > System.Net.Mail .SmtpClient("sm tp.myserveraddr ess.com");
>> > smtp.Send(mail) ;

"Swanand Mokashi" wrote:
Add the <mailSettings > block in <system.net> block in the web.config
file.
for e.g.
<system.net>
<mailSettings >
<smtp from="fr**@test .com">
<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

"theWizard1 " <th********@dis cussions.micros oft.com> wrote in message
news:FD******** *************** ***********@mic rosoft.com...
> 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.
>
> "sloan" wrote:
>
>> check my blog:
>> http://spaces.msn.com/sholliday/ 2/8/2006 entry
>>
>> I wrote a very nice (if I do say so my self) for having lots of
>> flexibility
>> with smtp server settings.
>>
>> There is a 2.0 and 1.1 example.
>>
>>
>>
>>
>> "theWizard1 " <th********@dis cussions.micros oft.com> wrote in message
>> news:64******** *************** ***********@mic rosoft.com...
>> > 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("sm tp.myserveraddr ess.com");
>> > smtp.Send(mail) ;
>>
>>
>>


Apr 20 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2069
by: Rajesh Abraham | last post by:
I have an assembly, which is reading some values from the App.Config file. It works fine when used with a Win Forms project. Now I am trying to use the same assembly in a Windows Service Project but the service fails to start as the assembly is not able to get the value from the app.config and hence throws an error. I tried adding app.config to the Win Service Project but it did not work.
2
2657
by: Anna | last post by:
I added a small Web.Config file to the root of my website so that I could view errors on a machine other than the server: <configuration> <system.web> <customErrors mode="Off" /> </system.web> </configuration> However, this immediately threw a different error when I tried to view
5
3386
by: feng | last post by:
Hi, We just converted our VB.Net Windows exe project from VS.Net 2002 to VS.Net 2003 and ran into a problem. the MyApp.exe.config file that we use for our customized configuration settings is removed when the conversion is done. It won't work even if I menully copy the file back. The settings are not get recogenized. What's going on? Thanks
10
3017
by: David Thole | last post by:
Hey all, I'm still very new at all this, but am going through the ASP.net 2.0 unleashed book, first chapter and trying to program my own little form emailer for fun. I tried following the code for their version in the book to the best of my abiltiies, and came across issues, mostly that a type was expected when trying to compile in MS Visual Studio 2002. When my stuff wasn't working at all, I decided to try just using his code almost...
0
2414
by: howardr101 | last post by:
Hi, Have hunted around on the groups and can't find anything, hence. I've tried this against 2 mail servers (mailtraq and hmailserver) and it occus with both. The problems seems to be that when the SMTPClient attaches to the server and the server sends it greeting message, if anything other than +OK is received by the client it throws an exception and falls over.
1
1702
by: Sammy | last post by:
I am using the following code on a company that hosts our web site. I have noticed lately that their mail server/smtp is unavailable several times a minute for a second or two. This is causing my script to fail when it calls the client.Send(msg); Will adding "client.Timeout = 1000000;" help my problem if the server can't be reached or does the timeout assume the server can be reached but waits for it to become less busy? // create...
6
2910
by: Peted | last post by:
Hi, im wanting to store some custom text strings in the app.config file of a c# app, to be retreived and updated when the app runs. using c# 2005 express in my testing i am using the code bellow, and its almost idenictal to every web example i have found. They all suggest the values and file can be read from and updated. The code bellow runs, with no errors of
6
5488
by: =?Utf-8?B?VG9yc3Rlbg==?= | last post by:
Hi, I have a problem sending mails with the SmtpClient class. It's strange - after I boot the pc and start the program I can send mails many times. After I close the program and start it again it sometimes works too, but often does not. If it does not, he will never - until the next reboot. Then the "game" starts again. I get the exception "'No connection could be made because the target machine actively refused it.". Telnet to port 25...
5
3920
by: BigDave | last post by:
Hi, I'm having problems with SmtpClient. I have the following set in my web.config: <configuration> <system.net> <mailSettings> <smtp> <network host="mysmtp" port="25" userName="myuser"
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10070
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.