Send Mail from ASP.Net

Tuesday, 22 May 2007 23:20 by scngan

Wondering how to send mail from your ASP.NET project ?  below is the VB.net sample code you can refer to use.
Send mail from ASP.NET uses  System.Net.Mail.SmtpClient class.

' Send mail from asp.net start point

Dim mailmsg As New System.Net.Mail.MailMessage
mailmsg.Priority = Net.Mail.MailPriority.High ' set the mail priority to high
mailmsg.IsBodyHtml = True ' declare the body of the mail to use HTML
mailmsg.Headers.Add("Disposition-Notification-To", "yourname@yourdomain.com") ' if you want to send a read notification when ppl read your mail
mailmsg.From = ("yourname@yourdomain.com")
mailmsg.To.Add("yourname@yourdomain.com")
mailmsg.CC.Add("yourname@yourdomain.com")
mailmsg.Bcc.Add("yourname@yourdomain.com")

mailmsg.Subject = "Your Mail Subject"
mailmsg.Body = "Your mail body"
Dim smtp As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient ' declare to use SMTP client class
smtp.Host = "Your SMTP Host" 'mail.yourdomain.com
smtp.Port = "25" 'your smtp port number
smtp.Credentials = New Net.NetworkCredential("yourname@domain.com", "your password")

smtp.Send(mailmsg) ' send the mail
mailmsg.Dispose() ' dispose the mail after you sent

'Send mail from asp.net end point

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   Technical Stuff
Actions:   | E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed
Comments are closed