12 September 2013

How to Send G-mail using vb.net

Today Samnengit will show you how to create G-mail Sender using Visual Basic 2010.


1. Create new form like Picture above

2. Draw 5 textbox and 1 button
- Username properties (Name) = txtusername
- Password properties (Name) = txtpassword, PasswordCha = *
- To properties (Name) = txtto
- Subject properties (Name) = txtsubject
- Body properties (Name) = txtbody
- Button Send mail properties (Name) = btnsend, Text = Send mail

3. Copy and Paste code below in the top

Imports System.Net
Imports System.Net.Mail

4. Double Click on button Send mail and write code below

Try
    Dim AnEmailMessage As New MailMessage
            AnEmailMessage.From = New MailAddress(txtusername.Text)
            AnEmailMessage.To.Add(txtto.Text)
            AnEmailMessage.Subject = (txtsubject.Text)
            AnEmailMessage.Body = (txtbody.Text)
            AnEmailMessage.Priority = MailPriority.High
    Dim SimpleSMTP As New SmtpClient("smtp.gmail.com")
            With SimpleSMTP
                .Port = 587
                .EnableSsl = True
                .Credentials = _
                New NetworkCredential(txtusername.Text, txtpassword.Text)
                .Send(AnEmailMessage)
            End With
              MsgBox("Email sent to : " & txtto.Text, MsgBoxStyle.Information)
   Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)

*** Note : It work only G-mail.

If it doesn't work or Error, you can comment to ask us about your problem. 



SamnengIT © 2014-2015SamnengIT