Imports Microsoft.VisualBasic
Imports System.Net.Mail
Public Class Cemail
Public Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, _
ByVal cc As String, ByVal subject As String, ByVal body As String)
Dim mMailMessage As New MailMessage()
mMailMessage.From = New MailAddress(from)
mMailMessage.To.Add(New MailAddress(recepient))
If Not bcc Is Nothing And bcc <> String.Empty Then
mMailMessage.Bcc.Add(New MailAddress(bcc))
End If
If Not cc Is Nothing And cc <> String.Empty Then
mMailMessage.CC.Add(New MailAddress(cc))
End If
mMailMessage.Subject = subject
mMailMessage.Body = body
mMailMessage.IsBodyHtml = True
mMailMessage.Priority = MailPriority.Normal
Dim mSmtpClient As New System.Net.Mail.SmtpClient()
mSmtpClient.Credentials = New Net.NetworkCredential("[email protected]", "passmail")
mSmtpClient.EnableSsl = True
mSmtpClient.Port = 587
mSmtpClient.Host = "smtp.gmail.com"
mSmtpClient.Send(mMailMessage)
mSmtpClient = Nothing
End Sub
End Class
เรียกใช้แบบนี้ครับ
Omail As new Cemail
Omail.SendMailMessage("จาก", TextBox4.Text, "", "", "หัวข้อ", "เนื้อหา")