Sending Mail using SmtpClient
October 29, 2007 at 9:37 am | In Dot Net | Leave a CommentImports System.Net.Mail
Protected Sub btnRegister_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRegister.Click
Dim smtpClient As New SmtpClient
Dim message As New MailMessage
Dim fromAddress As New MailAddress(host site mail address)
Dim toAddress As New MailAddress(receiver mail address)
Try
‘You can specify the host name or ipaddress of your server
‘ Default in IIS will be localhost
smtpClient.Host = “localhost”
‘Default port will be 25
smtpClient.Port = 25
‘From address will be given as a MailAddress Object
message.From = fromAddress
‘To address collection of MailAddress
message.To.Add(toAddress)
message.Subject = “Feedback”
‘// CC and BCC optional
‘// MailAddressCollection class is used to send the email to various users
‘// You can specify Address as new MailAddress(“admin1@yoursite.com”)
message.CC.Add(“admin1@yoursite.com”);
message.CC.Add(“admin2@yoursite.com”);
‘// You can specify Address directly as string
message.Bcc.Add(new MailAddress(“admin3@yoursite.com”));
message.Bcc.Add(new MailAddress(“admin4@yoursite.com”));
‘Body can be Html or text format
‘Specify true if it is html message
message.IsBodyHtml = False
‘Message body content
message.Body = [message as string]
‘Send SMTP mail
smtpClient.Send(message)
Response.Write(“alert(‘Email successfully
sent.’);”)
Catch ex As Exception
Response.Write(“alert(‘Email sent fail.’);”)
End Try
End Sub
No Comments Yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.