Sure.
Consider the code I provided in my last post:
string message = "Just a test email body";
//Define your SMTP host
SmptClient client = new SmtpClient();
client.Host = "localhost";
MailMessage msg = new MailMessage("<from address>", "<to address>");
msg.Subject = "Foo";
msg.Body = message;
client.Send(msg);
Now say that you had 6 different webforms that used this code but then you get a requirement that the Email Server Addressed has changed, you are going to have to go back to each of those 6 pages and change the Host property to the new Email Server.
To remedy this you could create a class and place a method in it like this:
public static void SendEmail()
{
string message = "Just a test email body";
//Define your SMTP host
SmptClient client = new SmtpClient();
client.Host = "localhost";
MailMessage msg = new MailMessage("<from address>", "<to address>");
msg.Subject = "Foo";
msg.Body = message;
client.Send(msg);
}
And then you could just make a call on all 6 of your Webforms like this: MyClass.SendEmail(). So using the secnario from earlier you now only would have to change the Host Field in one place which is much more effecient but this code isn't portable because you have physically tied the code to your Email Server!
So, by placing the values of your email server in the web.config you do not need to explictly define the address of the server in your code since they will be pulled from the web.config. By doing this you could take that code and drop it into any website, configure the values in the web.config and you are done.
Lastly, regarding Authentication and relaying, some servers require authentication to connect to the SMTP service (for example if you wanted to send mail through GMail, you need to provide your Gmail username and password before you can pass mail through their SMTP).
However, in the case of the Virtual SMTP server that runs with IIS there is no authentication information required, however, to enable relaying you have to configure the SMTP to allow it to relay messages from your machine.
hth.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========