Tuesday, September 05, 2006

Develop email applications using ASP.NET 2.0

In ASP.NET 1.x sending email was fairly simple.  The only issue was that there were different ways to send email depending on whether the application was web or windows based.  Windows developers used MAPI to send emails using an email client like Outlook.  Web developers used CDOSYS to send rich emails.  Microsoft realized that a change was warranted.  In ASP.NET 2.0 Microsoft released a new set of classes to handle email.  The only issue is that to many developers, sending email became much more complex.

In ASP.NET 2.0 a new group was added that contains configurable sections for the System.Net namespace called the system.net section group.  This group allows email settings to be established by using the mailSettings section group.  Since we are sending emails and not receiving emails, we will use the SMTP protocol.  To define the SMTP settings, we will add the SMTP section group to the mailSettings section group.  The SMTP section group then contains a network section that specifies attributes for the SMTP network settings.  These attributes include host, port, username, and password.

To prevent confusion, in ASP.NET 2.0 the System.Web.Mail namespace has been marked deprecated.  All of the classes are still accessible using IntelliSense and will still function properly.  However, they too are marked obsolete.  Instead, a new namespace found at System.Net.Mail should be used.  This new namespace contains classes to manage your mail client and messages.  The SmtpClient class is used to establish a host, port, and network credentials for your SMTP server.  The MailMessage class is similar to the MailMessage class found in the old System.Web.Mail namespace.  This class allows a full email message to be built.  There is also an Attachment class that allows an attachment to be generated so it can later be added to the MailMessage object.  In addition to these three most commonly used classes, you will find that System.Net.Mail contains an AlternateView and LinkedResource class.

Unfortunately, ASP.NET 2.0 does not provide a clean and easy way to access the system.net section group from the web.config file within code.  The SmtpClient object contains a UseDefaultCredentials boolean property, but that specifies whether the SmtpClient object is to use the credentials of the user currently running the application.

Read more

Can't find what you're looking for? Try Google Search!
Google
 
Web eshwar123.blogspot.com

Comments on "Develop email applications using ASP.NET 2.0"