Wednesday, October 22, 2008

Sending Email in VB2005

Here is an example code to send email using VB2005. We have used gmail to illustrate it and you need to have a gmail account to test it.

Imports System.Net.Mail Public Sub SendMail() Dim mail As New MailMessage() 'set the addresses mail.From = New MailAddress("") mail.To.Add("") 'set the content mail.Subject = "Sample Subject" mail.Body = "This is a body" 'send the message Dim smtp As New SmtpClient("", 587) smtp.Credentials = New System.Net.NetworkCredential("", "yourpassword") smtp.EnableSsl = True Try smtp.Send(mail) Catch ex As Exception MsgBox(ex.ToString()) End Try End Sub

No comments:

Post a Comment

Comments are moderated and don't be surprised if your comment does not appear promptly.