Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendemail.Click
Try
Dim send As String = TextboxFrom.Text.Trim
Dim pw As String = textboxPass.Text.Trim
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential(send, pw)
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress(textboxFrom.Text)
e_mail.To.Add(textboxTo.Text)
e_mail.Subject = textboxSubject.Text.Trim
e_mail.IsBodyHtml = False
e_mail.Body = textCompose.Text
Smtp_Server.Send(e_mail)
MsgBox("Mail Sent")
Me.Close()
Me.Dispose()
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
End Sub
Nguồn: Sharecode.vn