Monday, July 23, 2012

How to send Email using VB...?


Today iam explaining you about how to send emails from asp.net using vb

Its really very simple.
Simple simple.

Just create an asp.net web site and put control related to the objects used in the following code.

This is the code. just try it.Its working finely.

Imports System.Net.Mail
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim smtpServer As New SmtpClient()
        Dim mail As New MailMessage
  smtpServer.Credentials = New Net.NetworkCredential(TextBox1.Text &     "@gmail.com", TextBox2.Text)
        smtpServer.Port = 587
        smtpServer.Host = "smtp.gmail.com"
        smtpServer.EnableSsl = True
        mail.From = New MailAddress(TextBox1.Text & "@gmail.com")       
        mail.To.Add(TextBox3.Text)
        mail.Subject = TextBox4.Text
        mail.Body = TextBox5.Text()
        smtpServer.Send(mail)
        MsgBox("mail is sent", MsgBoxStyle.OkOnly, "Report")
    End Sub

        
End Class

No comments: