?
Solved

Send email confirmation in VB.NET

Posted on 2008-11-04
5
Medium Priority
?
389 Views
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()
mSmtpClient.Send(mMailMessage)
 
End Sub

Open in new window

0
Comment
Question by:OVC-it-guy
  • 4
5 Comments
 
LVL 11

Accepted Solution

by:
ladarling earned 2000 total points
ID: 22879504
You need to change your import from System.Web.Mail to System.Net.Mail.
The two objects you will most likely be interested are:
System.Net.Mail.MailMessage
System.Net.Mail.SmtpClient
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
 
0
 

Author Comment

by:OVC-it-guy
ID: 22879762
Let me try that and fill in the parameters.
0
 

Author Comment

by:OVC-it-guy
ID: 22880449
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,
mSmtpClient.Send(mMailMessage)
 
0
 

Author Comment

by:OVC-it-guy
ID: 22880470
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?
0
 

Author Comment

by:OVC-it-guy
ID: 22880628
I remember it being something like this:

<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="me@omahavaccine.com">
        <network defaultCredentials="true" host="localhost" port="25" userName="myusername" password="mypassword"/>
      </smtp>
    </mailSettings>
  </system.net>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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 …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

839 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