vb.net send email outlook code example
Example: send email from vb.net
Imports System.Net.Mail
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txtPass.PasswordChar = Chr(149)
End Sub
Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
Try
Dim mail As New MailMessage
Dim smtpServer As New SmtpClient("smtp.outlook.com")
mail.From = New MailAddress(txtFrom.Text)
mail.To.Add(txtTo.Text)
mail.Subject = txtSubject.Text
mail.Body = txtMessage.Text
smtpServer.Port = 587
smtpServer.Credentials = New System.Net.NetworkCredential(txtFrom.Text, txtPass.Text)
smtpServer.EnableSsl = True
smtpServer.Send(mail)
MsgBox("Your email has been sent", MessageBoxIcon.Information, MessageBoxButtons.OK)
Catch ex As Exception
MsgBox(ex.Message, vbCritical)
End Try
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class