Wednesday, March 15, 2006

Long ago ..... System.Web.Mail

Hi all,
Its been quite a while since i posted on my blog. I was terribly busy(emotionally disturbed, so took a two week break and i did nothing but "eat,sleep,watch movie,freak with friends"). Anyway the following is the steps you need to do, to send email from .NET application using System.Web.Mail.
1. Add reference to System.Web.dll if it its not already added(for asp.net applications, its already added, so you can skip this)
2. Import the namespace System.Web.Mail
3. Customize the following code
'a) Prepare your message
Dim msg as new MailMessage
msg.To = "to@email.com"
msg.From = "from@email.com"
msg.Subject = "Your subject goes here"
msg.Body = "Body of email"
'b) Send your message
SmtpMail.SmtpServer="smtpserveraddress"
SmtpMail.Send(msg) 'sending the mail.

As you notice, its pretty simple to work with!! But it isnt as simple as it appears. Just for information, Web.Mail uses CDOSYS internally to communicate with SMTP server and this is considered bad(i dont have enough experience to tell why, but its bad from what i read) .
Also another question is "What if my SMTP Server needs authentication?" Well this question has haunted me for two years and have now found out the answer. Just check out this cool support topic from MSDN.
http://support.microsoft.com/default.aspx?scid=kb;en-us;555287

Well there are sooo many issues with System.Web.Mail that there is a dedicated site for the namespace !!! check out www.systemwebmail.com !!! Cool

Also for your information, for .NET 2.0 use System.Net.Mail namespace - which actually makes sense. That is all for now and i have another problem to figure out. I noticed that Query Strings end when they encounter "#" I mean if actual string is Pa=1&Pg=2&Name=C#&Value=CS,when you read that string inside the asp.net applicaiton using "Request.QueryString", all you can see is that its only Pa=1&Pg=2&Name=C and #&Value=CS is skipped!!! Any solution for this?? Comment on my blog.

1 comment:

Krishna Bhargava Vangapandu said...

Well I got the solution by myself. Just use URL Encoding for the values and prepare the String. Thats it!