How To Send Email Message In .NET
May 14, 2008 – 6:04 amLast day i see some question in one best forum for programming that want to know how to send an email using .NET.
I have some experience when i work in one dutch project (’ TennisSite ‘) by Wellfound and have a module for send an email for customer.
So i will explain it here, about how to send an email using .NET. We use System.Net.Mail namespace for this project.
Ok this is the code snippet for send an email using .NET
Dim strUserName As String = "" ‘Username for smtpclient
Dim strPassword As String = "" ‘user password for smtpclient
Dim strHostName As String = "" ’smtpaddress
Dim intPort As Integer = 25
Dim credentials As New System.Net.NetworkCredential(strUserName, strPassword)
Dim message As New MailMessage()
Dim emailClient As New SmtpClient(strHostName, intPort)
With message
.From = New MailAddress(strUserName)
.To.Add(txtSendTo.Text.Trim)
.Subject = "Test Send Email"
.Body = txtMessage.Text.Trim
.IsBodyHtml = True
.Attachments.Add(New Attachment("path of file")
.Bcc.Add("email address")
.CC.Add("email address")
End With
emailClient.Credentials = credentials
Try
emailClient.Send(message)
Catch ex As Exception
MsgBox(ex.Source & " : " & ex.Message, MsgBoxStyle.Exclamation, "Error Message")
Finally
message = Nothing
emailClient = Nothing
End Try
I hope this article will help you in your some application project for send an email in future.


One Response to “<b>How To Send Email Message In .NET</b>”
bagus bgt. aq dah bisa kirim email pake .NET.
tp, tanpa content-type di Attachment, aq gagal terus. stlh dikasi content-type (parameter ke-2 di constructor Attachment), baru sukses. knp ya??
By alvin on Jul 7, 2008