Sending Emails With ASP.Net

If you haven’t checked into it yet, there are several things that have changed from ASP.Net1.1 and ASP.Net 2.0, concerning email, however, it’s still not very complicated.

The first thing you’ll notice is that the namespace has changed from System.Web.Mail to System.Net.Mail. Also, now, to get the email working, there are two classes that need to be addressed:

  • MailMessage()
  • SmtpClient()

To use these, it will look something like this:

Dim Msg as MailMessage = new MailMessage()
Dim MailObj As New SmtpClient("mail.YourDomain.com")

Now – to add your To and From addresses, the Subject, Body and Body type, you’d do something like this:

Msg.From = new MailAddress("me@Here.com", "Big D")
Msg.To.Add(new MailAddress("you@There.com", "Knot A. Wildone"))
Msg.IsBodyHtml = "False"
Msg.Body = "this is the Email body"
Msg.Subject = "This is the Subject"

Notice, that the ‘Friendly’ name, can be easily added as a second argument, along with the direct email address. And Finally, to actually send the message, one line needs to be added:

MailObj.Send(msg)

Of course, if you needed some sort of confirmation statement, you could then add something like this:

label1.text="Email Sent!"

As was said earlier, several things have changed, and, it’s not quite as easy as it was with ASP.Net version 1.1, but still, emailing in ASP.Net remains a very easy accomplishment!

Related Posts:

  • No Related Posts
Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!