.: Easy Soft Technologies :.

May 14, 2008

How To Send Email Message In .NET

Last 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.

1 Comment »

The URI to TrackBack this entry is: http://easysoft.blogsome.com/2008/05/14/how-to-send-email-message-in-net/trackback/

  1. 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??

    Comment by alvin — July 7, 2008 @ 4:31 pm

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome
Theme designed by Jay of onefinejay.com