Cara mengirim email di VB.NET dengan smtp server google (gmail)


Terkadang ada situasi dimana kita membuat konsep yang ada proses mengirim email pada VB.NET. Berikut saya akan share code untuk mengirim email via VB tapi harus dengan Gmail account.
Berikut syntaxnya (anda bisa membuat otomatis atau memanggilnya dalan sub) :

Private Sub kirimemail ()
Try
  Dim mail As MailMessage = New MailMessage()
  Dim SmtpServer As SmtpClient = New SmtpClient("smtp.gmail.com")
  mail.From = New MailAddress("mapjogja@gmail.com")
  mail.To.Add("userid@ymail.com")
  mail.Subject = "TEST EMAIL"
  mail.Body = "isi email"
  SmtpServer.Port = 587
  SmtpServer.Credentials = New System.Net.NetworkCredential("userid@gmail.com", "passwordemail")
  SmtpServer.EnableSsl = True
  SmtpServer.Send(mail)
  MessageBox.Show("Email Terkirim")

  Catch ex As Exception
  MsgBox(ex.Message.ToString)
End Try
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s