Help with email confirmation code in VBScript for Web site

easyeman

Active member
Joined
Nov 16, 2005
Messages
28
Location
Decatur, AL
Programming Experience
1-3
I need some help. I am trying to write code for an email confirmation thing, so when customers order something off a web site, then it will send them a confirmation message to let them know what they ordered and that it was accepted. But it doesn't seem to be working. I have posted the code below in case anyone wants to look it over and see what the problem could be. I have it set up as an ArrayList which I believe is the problem, so it may need to be an array, dataset, datatable, etc...but not sure what.

Can anyone give me input or suggest what to change, and by all means try it out yourself and maybe see if you can get the code working. I think I posted this at another forum earlier and got no response, and I haven't worked on this in a couple months since I got busy with other projects. But I need to get this finished and working as soon as I can, and since I know there are bigger experts on here than me, I could use the help haha.

This is VBScript type code, but I did it in Visual Web Developer so I just set it up as that. Not sure if this is the right place for this question since it is more VBScript and not VB.net. Anyway, thanks for any help and input and hopefully I can get this working correctly with your help. I'll go ahead and use my company's name and such in here so it will be like it should.

VB.NET:
Public Class Email
    Const eServer As String = "virtmail.deltacom.net"
    Const eFrom As String = "NAFECO Webstore <webstore@nafeco.com>"
    
    Public Sub NewAccountEmail (ByVal Email As String, ByVal LoginID As String)
        Try
            Dim NewCustEmail As New MailMessage
            Dim NewNotifyEmail As New MailMessage
            
            'Set Customer Email propertiesa
            With NewCustEmail
                .From = eFrom
                .To = Email
                .Subject = "New NAFECO Webstore Account"
                .Body = "Welcome to nafeco.com!  We know you have many choices regarding where to shop online, and we greatly value your business." _
                & Chr(10) & Chr(10) & "As a nafeco.com customer, we want you to feel welcome and to make sure you have everything you need to make your shopping experience easy " _
                "and enjoyable.  If you have any questions, please feel free to email us at [EMAIL="help@nafeco.com"]help@nafeco.com[/EMAIL] or call us at 1-800-628-6233." _
                & Chr(10) & Chr(10) & "The nafeco.com WebStore Account you just set up allows you to order from our wide selection of products using our Secure Internet server. " _
                "Rest assured that all of your personal information remains private and secure at all times.  We take your privacy seriously and we never give out or sell your information." _
                & Chr(10) & Chr(10) & Chr(10)_
                & "Sincerely," & Chr(10) & Chr(10)_
                & "NAFECO WebStore Team" & Chr(10)_
                & "nafeco.com" & Chr(10)& Chr(10) & Chr(10)_
                & "Your Account User Name Is: " & LoginID
            End With
            
            'Set Notification Email properties
            With NewNotifyEmail
                .From = eFrom
                .To = "ehagemann@nafeco.com"
                .Subject = "New Customer Account Created: " & LoginID
                .Body = "Login: " & LoginID & Chr(10) & "Email: " & Email
                .Priority = MailPriority.High
            End With
            
            'Set Email server and send mail
            SmtpMail.SmtpServer = eServer
            SmtpMail.Send(NewCustEmail)
            SmtpMail.Send(NewNotifyEmail)
            
        Catch ex As Exception
        
        End Try
    End Sub
    
    Public Sub OrderConfirmationEmail (ByVal Email As String, ByVal LoginID As String, ByVal OrderNumber As String, _
    ByVal Qty As ArrayList, ByVal PartNum As ArrayList)
        Try
            Dim NewCustEmail As New MailMessage
            Dim NewNotifyEmail As New MailMessage
            Dim Body As String
            
            Body = Today() & Chr(10) & LoginID & ":" & Chr(10) & Chr(10)_
            & "Thank you for choosing NAFECO. We have received your online order."_
            & Chr(10) & Chr(10) & "Order Number: " & OrderNumber_ 
            & Chr(10) & Chr(10)_
            & "Qty" & Char(9) & "ProductID" & Chr(9) & "Description" & Chr(9) & Chr(9) & Chr(9) & "Price" & & Chr(10)_
            & "--------------------------------------------------------------------------" & Chr(10)
            
            Dim q As IEnumerator
            q = Qty.GetEnumerator
            Dim p As IEnumerator
            p = PartNum.GetEnumerator
            
            Do While q.MoveNext()
                p.MoveNext()
                Body = Body & CType(q.Current, String) & Chr(9) & CType(p.Current, String) & Chr(10)
            Loop
            
            'Set Customer Email properties
            With NewCustEmail
                .Body = Body
                .From = eFrom
                .To = Email
                .Subject = "NAFECO Order Confirmation"
            End With
            
            'Set Notification Email properties
            With NewNotifyEmail
                .From = eFrom
                .To = "ehagemann@nafeco.com"
                .Subject = "New Customer Account Created: " & LoginID
                .Body = "Login: " & LoginID & Chr(10) & "Email: " & Email
                .Priority = MailPriority.High
            End With
            
            'Set Email server and send mail
            SmtpMail.SmtpServer = eServer
            SmtpMail.Send(NewCustEmail)
            SmtpMail.Send(NewNotifyEmail)
            
        Catch ex As Exception
        End Try
End Sub
 
ARGH I feel like an idiot. lol well it's not in VBscript...it's in VB.net. I have no idea why I was thinking it was VBScript, so that's probably why I can't figure it out and it may have confused some of you. Sorry about that

It's VB.net, not Script, so maybe that'll help us figure out what to do. I'll be reading up to see on how to make it work, but any suggestions would be nice also. Thanks
 
thanks for the reply...well honestly I'm about as lost as you. Someone that works here tried to do it and used that ArrayList but could not get it to work, but never told me exactly what was wrong...I assume it just wouldn't work, so he asked me to look at it.

Sadly I'm not 100% familiar with VB.net so I'm having some trouble, but basically I guess all that needs to be done is sending those emails out which tells the customer what they ordered, quantity, and price of each item. I guess the Arrays are needed to go through each item they order and grab it from the system to post into the email and let them know.

Honestly, if we need to just redo the whole code then that'd be great. I guess mainly we just need to automatically send emails when people place an order and it tells them what they ordered (part number and title description, quantity, and price) and then at the end it can have net amount, total freight, and then total amount due for the order...just so they know it's been received. Let me know if that makes sense but I guess that's all we need and I can supply an example of what it can look like...I guess I'm just lost with that code and trying to fix it, but overall it may just be unnecessary.

I know someone suggested making just one arraylist and having another class just to define variables. But I need help in just how to set up code for making an automated email response for customers placing orders. So it shouldn't be too tough but apparently I can't figure it out haha. Thanks for the help in advance.
 
Ok i would use a session object in this case. Also make a Sub sendEmail() and pass the parameters in it ... i.e.

VB.NET:
Private Sub sendEmail(byVal strEmail As String, ByVal strAddress as String, ByVal strName as String, ByVal strProduct as String, etc... )
   Dim objMM as New MailMessage()
   objMM.To = myMsg
   objMM.From = "[EMAIL="info@domain.com"]info@domain.com[/EMAIL]"
   objMM.BodyFormat = MailFormat.Html
   objMM.Priority = MailPriority.Normal
   objMM.Subject = "New Order"
 
   Dim strBld As New StringBuilder
  With strBld
.Append("<b>" & "Informations about the User:" & "</b>")
.Append("<br><br>")
.Append("Sender's email: " & Session("myEmail"))
.Append("<br>")
.Append("Sender's first name: " & Session("myfName"))
.Append("<br>")
.Append("Sender's last name: " & Session("mylName"))
.Append("<br>")
.Append("Sender's home phone: " & Session("myhPhone"))
.Append("<br>")
.Append("Sender's work phone: " & Session("mywPhone"))
.Append("<br>")
.Append("Best time to call: " & Session("myBestTime"))
.Append("<br>")
.Append("Sender's street address: " & Session("myStreet"))
.Append("<br>")
.Append("Sender's city: " & Session("myCity"))
.Append("<br>")
.Append("Sender's state: " & Session("myState"))
.Append("<br>")
.Append("Sender's zip code: " & Session("myZip"))
.Append("<br>")
.Append("User's IP/Proxy: " & System.Web.HttpContext.Current.Request.UserHostAddress)
.Append("<br><br><br>")
.Append("<br>")
.Append("<b>" & "the user slected next from our offer:" & "</b>")
.Append("<br>")
.Append("<br>")
.Append("Products: ")
.Append(strProduct)
.Append("<br>")
.Append("Quantity: ")
.Append(strQuantity) [COLOR=darkgreen]'you can continue with anything else you want[/COLOR]
.Append("<br>")
.Append("<font size='1' color='#cccccc'>")
.Append("yourcompany.com")
.Append("<br>")
.Append(Date.Now)
.Append("</font>")
End With
'Set the body
objMM.Body = strBld.ToString()
 
  SmtpMail.SmtpServer = "mail.server.net" [COLOR=darkgreen]'replace with adequate SmtpServer[/COLOR]
  SmtpMail.Send(objMM)
End Sub

Now you can simply call this procedure whenever you want to send an email ... all you need is to pass values for parameters

i.e. Button Submit event:
VB.NET:
sendEmail(" [EMAIL="myname@domain"]myname@domain[/EMAIL] ", txtAddress.Text etc....)
[COLOR=darkgreen]'also for the user[/COLOR]
sendEmail(Session("myEmail"), txtAddress.text etc....) 'where Session("myEmail") is object that holds the user's email


HTH
Regards ;)
 
Well I'm back again, but I finally have it working and just need help in a more specific area for now.

I changed up some of the code and it was working when I ran it through yesterday. The main thing I need help with is getting the output to look good. I'll post the code below so you see what I did, and I can try to display the output here of what it would do. Basically I'm deciding on just making it a text based output rather than HTML so everyone can view it. But of course it doesn't want to space correctly.

The one idea I had was setting up an if statement that basically checks if the variable name is less than the max length of what it can be, then it will add spaces to fill it up. In my thinking, this will keep things spaced out so it looks good in output...and I need this for all the main items such as item number, quantity, description, and price. But it is working since it sends the email, so basically all I need to know now is how to get the output to look aligned and decent. So any ideas and tips would help. Once I get that down, then it shouldn't be too tough to finish it.

Thanks for the help!

VB.NET:
Imports System.Net.Mail

Partial Class _Default
    Inherits System.Web.UI.Page

    Const eServer As String = "virtmail.deltacom.net"
    Const eFrom As String = "NAFECO Webstore <webstore@nafeco.com>"

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim qty As ArrayList = New ArrayList()
        Dim partnum As ArrayList = New ArrayList()
        Dim description As ArrayList = New ArrayList()
        Dim price As ArrayList = New ArrayList()


        qty.Add(1)
        qty.Add(5)
        qty.Add(9)
        partnum.Add("5225-XL")
        partnum.Add("25")
        partnum.Add("1715")
        description.Add("GLOVE")
        description.Add("FITTING")
        description.Add("NOZZLE")
        price.Add(30.0)
        price.Add(10.0)
        price.Add(250.0)


        OrderConfirmationEmail("jbowling@nafeco.com", "jkbowling", "12345", qty, partnum, description, price, 250.0, 25.0, 30.0, 285.0)


    End Sub

    Public Sub OrderConfirmationEmail(ByVal Email As String, ByVal LoginID As String, ByVal OrderNumber As String, _
            ByVal Qty As ArrayList, ByVal PartNum As ArrayList, ByVal Description As ArrayList, ByVal Price As ArrayList, ByVal subtotal As Decimal, _
            ByVal Tax As Decimal, ByVal Freight As Decimal, ByVal Total As Decimal)
        Try
            Dim msg As New MailMessage
            Dim addressFrom As New MailAddress(eFrom)
            Dim addressTo As New MailAddress(Email)
            Dim addressCC As New MailAddress("ehagemann@nafeco.com")

            Dim Body As String

            Body = Today() & Chr(10) & LoginID & ":" & Chr(10) & Chr(10) _
            & "Thank you for choosing NAFECO. We have received your online order." _
            & Chr(10) & Chr(10) & "Order Number: " & OrderNumber _
            & Chr(10) & Chr(10) _
            & "Qty" & Chr(9) & "ProductID" & Chr(9) & "Description" & Chr(9) & Chr(9) & Chr(9) & "Price" & Chr(10) _
            & "--------------------------------------------------------------------------" & Chr(10)

            Dim i As Integer
            

            For i = 0 To PartNum.Count - 1
                Body = Body & Qty(i) & Chr(9) & partnum(i) & Chr(9) & description(i) & Chr(9) & price(i) & Chr(10)
            Next


            'Set Message properties
            With msg
                .Body = Body
                .From = addressFrom
                .To.Add(addressTo)
                .CC.Add(addressCC)
                .Subject = "NAFECO Order Confirmation"
            End With

            'Set Email server and send mail
            Dim smtp As SmtpClient = New SmtpClient
            smtp.Host = eServer
            smtp.Send(msg)

        Catch ex As Exception
            'DO NOTHING FOR NOW
        End Try
    End Sub


End Class
 
Also here's an idea of what I wanted for the output, but that can be changed to I guess, just want it to look decent and just an idea I had....this is what it generates right now:

11/29/2005
jkbowling:

Thank you for choosing NAFECO. We have received your online order.

Order Number: 12345

Qty ProductID Description Price
--------------------------------------------------------------------------
1 5225-XL
5 25
9 1715


Basically I want the text aligned so it's spaced out enough just like it would look in a table, so the product ID will be right below that heading, price right below that heading, etc.

Qty....ProductID................Description...............................Price
--------------------------------------------------------------------
1.......5225-XL..................PIGSKIN GLOVES, XL...................30.00
5.......25..........................ADAPTER..................................15.00
9.......1715.......................NOZZLE...................................250.00

Subtotal: $295.00
Tax: $23.50
Freight: $20.00

Total: $338.50

^ something like that if that sounds ok to you. That way it just has whatever they wanted line by line and the info of it out to the side, and then it would need the Subtotal, then Tax and Freight and then the Total Amount at the end of it.

Hopefully it shouldn't be too difficult but it at least aligns the text so it makes a good output for the customer in a text format, and has the message before, so I mainly want to know how to get the text to look like that if anyone can help. I had a couple other ideas for output which could work but this should be good since it seems to align it the best and forms more of a table which customers can easily see and follow. Thanks again for the help!!

NOTE: When I tried to post the first time it took out all those spaces and bunched it, so I added periods to separate text, so for the actual output I'd want it to only have spaces if that can work, and not have those periods. Thanks again!
 
Back
Top