kali ini saya mencoba membagi pengetahuan tentang vb.net. Kita sering mengirim surat dengan menggunakan email, nahh sekarang saya akan membagi bagaimana membuat program sederhana VB.NET untuk mengirim email kitagunakan GMAIL .
Susun tampilan form seperti gambar dibawah ini :
dan masukan Sorcecode :
Imports System.Net.Mail
Public Class Form1
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End
End Sub
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.Credentials = New Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
smtpServer.Port = 587
smtpServer.Host = "smtp.gmail.com"
smtpServer.EnableSsl = True
mail.From = New MailAddress(TextBox1.Text & "@gmail.com")
'mail.From = New MailAddress(TextBox1.Text)
mail.To.Add(TextBox3.Text)
mail.Subject = TextBox4.Text
mail.Body = TextBox5.Text()
Try
smtpServer.Send(mail)
MsgBox("mail is sent", MsgBoxStyle.OkOnly, "Report")
Catch ex As Exception
MsgBox(ex.Message())
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox5.Clear()
TextBox5.Focus()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
0 komentar:
Posting Komentar