Rabu, 21 Desember 2011

Send Email By SMTP

Imports System.Net.Mail


Public
Sub SendEmail()

Dim client As New SmtpClient()
Dim sendTo As New MailAddress("sendToAccount@gmail.com")
Dim from As MailAddress = New MailAddress("from@address.com")
Dim
message As New MailMessage(from,sendTo)


message.IsBodyHtml = True
message.Subject = "Test SMTP"
message.Body = "Got it!!"

' Use the same account in app.config to authenticate.
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("yourAccount@xxx.com", "YourPassword")


client.Host = "smtp.xxx.com"
client.UseDefaultCredentials = False

client.Credentials = basicAuthenticationInfo

'' For smtp config
'' google use EnableSsl=True and Port = 587

client.EnableSsl = False
client.Port = 25

Try

client.Send(message)
Console.WriteLine("SUCCESS")

Catch ex As Exception

Console.WriteLine("SEND FAIL")

End Try

End Sub

Send Email By SMTP Rating: 4.5 Diposkan Oleh: dragon
Terima kasih sudah berkomentar