how to send mail


Simply a DIGITian
Staff member
Imports System.Net.Mail

Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
Dim message As String

SmtpServer.Credentials = New Net.NetworkCredential(<EMAILID>,<PASSWORD>)
'Only Needed if Your SMTP Port is Not the Default One.
SmtpServer.Port = 587
SmtpServer.Host = <MAIL SERVER> (Eg.
mail = New MailMessage()
mail.From = New MailAddress(<EMAILID>)
mail.Subject = <SUBJECT>

message = "Hello World"

mail.Body = message

'This blocks main thread until mail is sent
'MsgBox("mail send")

Dim userState As Object = mail

'Do this if you want to handle event manually, otherwise follow the below statement for sending mail asynchronously i.e. by not blocking the main thread.

'wire up the event for when the Async send is completed
'AddHandler SmtpServer.SendCompleted, AddressOf SmtpClient_OnCompleted

SmtpServer.SendAsync(mail, userState)

Hope that helps...

The code is in VB.NET, but in C# the procedure is same.

BTW, A simple google reveals...

Top Bottom