Posts

Showing posts from February, 2009

Sending Mail by Configuration in .NET

Sending mail is an activity required in many applications. The SMTP protocol is clearly defined in RFC 821 in the last century. It is a beautiful piece of work and this can be acknowledged by the fact that it has remained largely unchanged since. Microsoft's .NET has all the classes in the System.Net.Mail namespace to make sending mail a breeze. You can read through the documentation and Google for the many examples and tutorials if you are new to this subject. What I would like to share today is that sending mail in .NET can be made even easier by configuration. The following two lines of code are all that are needed to send out a mail: MailMessage msg = new MailMessage("x@gmail.com","bgates@microsoft.com", "Test","This is a test"); new SmtpClient().Send(msg); There is no need to embed in your code SMTP server names or passwords. That is bad practice because when you deploy your...