Send email confirmation in VB.NET

Posted on 2008-11-04
Last Modified: 2012-08-14
I have a web site done in ASP.NET with VB.NET.  I need to send an email confirmation of an online order after the customer checks out.  I have some code (see snippet) but MS Visual Web Developer doesn't like the MailMessage and several other parts, saying they're obsolete.  Will someone please tell me what the current (looking for .NET 3.5, but 2.0 may do) code for that?  I call the Sub on page-load.
Public Shared 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 SmtpClient()


End Sub

Open in new window

Question by:OVC-it-guy
    LVL 11

    Accepted Solution

    You need to change your import from System.Web.Mail to System.Net.Mail.
    The two objects you will most likely be interested are:

    Author Comment

    Let me try that and fill in the parameters.

    Author Comment

    Filled everything in, placed a test order and when the email routine was triggered I get an error "SMTP host was not specified," referring to the line,

    Author Comment

    I seem to recall something about setting that in the web.config file.  Do you know, can you tell me what I am missing / should have?

    Author Comment

    I remember it being something like this:

          <smtp deliveryMethod="Network" from="">
            <network defaultCredentials="true" host="localhost" port="25" userName="myusername" password="mypassword"/>

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now