Showing posts with label email. Show all posts
Showing posts with label email. Show all posts

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

send an email using only code in vb.net

In this tutorial, we will learn how to send an email using only code. The example in this tutorial will show you how to send an email by connecting to the googlemail SMTP server. If you want to send an email using another service such as hotmail or yahoomail, you will need to google for the SMTP host and port for that particular service. Modify the code like this give text boxes for subject, add, from etc. First line of code is declare mail as mail message, next line is subject of sending mail, next line enter your mail, and to mail, and body of the mail. Next line is setup smtpclient of google and send mail 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("youremail@googlemail.com")
        Mail.From = New MailAddress("youremail@googlemail.com")
        Mail.Body = "This is an ownage email using VB.NET"

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

End Class