Sunday, 12 August 2012

sending an email by connecting to an SMTP server using VB.NET

In the previous tutorial, we covered sending an email by connecting to an SMTP server using VB.NET. In this tutorial, we will create a Graphical User Interface for the user. As I mentioned in previous article making User Interface of your sending mail add 3 textboxes design as per you required and the extra things in this is adding user name, password, body of letter, from e-mail, to e-mail and subject etc. make good User Interface is better practice and good reputations you application Copy and paste below Code: 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 Mail As New MailMessage
        Mail.Subject = "test email"
        Mail.To.Add(TextBox2.Text)
        Mail.From = New MailAddress(TextBox2.Text)
        Mail.Body = TextBox1.Text

        Dim SMTP As New SmtpClient("smtp.gmail.com")
        SMTP.EnableSsl = True
        SMTP.Credentials = New System.Net.NetworkCredential(TextBox2.Text, TextBox3.Text)
        SMTP.Port = "587"
        SMTP.Send(Mail)
    End Sub

End Class