Results 1 to 4 of 4

Thread: Stringbuilder.Appendline not working sending email

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Stringbuilder.Appendline not working sending email

    Hello all,

    I'm building a string using stringbuilder and sending the results in an email. If I view the stringbuilder in debug mode it looks just fine. Here is how it looks in debug mode (ie ?sb.tostring):

    "ORDER DETAILS
    Fragrance: Chocolate Mocha Delight | Quantity: 1 | Price: $10.00 | Total:$11.50
    Fragrance: Decadent Strawberry Shortcake | Quantity: 1 | Price: $10.00 | Total:$11.50
    Fragrance: Pecan Pie | Quantity: 1 | Price: $10.00 | Total:$11.50
    Order Total: $33.00
    "
    This is the correct way. It should look like this in my email

    However when I recieve the email, it looks like the stringbuilder.appendline did not happen. It looks like this in my email:
    ORDER DETAILS Fragrance: Chocolate Mocha Delight | Quantity: 1 | Price: $10.00 | Total:$11.50 Fragrance: Decadent Strawberry Shortcake | Quantity: 1 | Price: $10.00 | Total:$11.50 Fragrance: Pecan Pie | Quantity: 1 | Price: $10.00 | Total:$11.50 Order Total: $33.00

    Here is my code:
    Code:
    Dim Dollars As Double = 0
            Dim EmailMessage As Email = New Email
            EmailMessage.AddRecipient("[email protected]")
            EmailMessage.subject = "New order from " & txtLastName.Text & ", " & txtFirstName.Text
    
            Dim sb As StringBuilder = New StringBuilder
            sb.Appendline("ORDER DETAILS")
    
            For Each dr As datarow In Cart.dtShoppingCart.Rows
                sb.Append("Fragrance: ")
                sb.Append(dr.Item("ProductName"))
                sb.Append(" | ")
                sb.Append("Quantity: ")
                sb.Append(dr.Item("Quantity"))
                sb.Append(" | ")
                sb.Append("Price: ")
                Dollars = dr.Item("ListPrice")
                sb.Append(Dollars.ToString("c"))
                sb.Append(" | ")
    
                If Cart.dtShoppingCart.Rows(0)("WickInd") = True Then
                    sb.Append("Wick included | ")
                    sb.Append("Total:")
                    Dollars = (dr.Item("ListPrice") + dr.Item("WickPrice")) * dr.Item("Quantity")
                    sb.Appendline(Dollars.ToString("c"))
               
                Else
                    sb.Append("Total:")
                    Dollars = (dr.Item("ListPrice") + dr.Item("WickPrice")) * dr.Item("Quantity")
                    sb.Appendline(Dollars.ToString("c"))
                    
    
                End If
    
            Next dr
            Dollars = Cart.ShoppingCartTotal
            sb.Appendline("Order Total: " & Dollars.ToString("c"))
    
            EmailMessage.body = sb.ToString
    
    
            EmailMessage.Send()
    I also tried using the ascii carriage return (ie chr(13)) and I still get the same result. I also have the isbodyhtml property set to true in my email class. I'm using ASP.NET 2.0 and VB2005.

    Anyone know the correct syntax?

    Thanks,

    Strick

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: Stringbuilder.Appendline not working sending email

    The code doesn't format the email as HTML (no <head> tags, etc). Try swapping it to plain text & use Environment.NewLine to introduce a new line if AppendLine continues to "malfunction"

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Stringbuilder.Appendline not working sending email

    In case you are sending the email contents in HTML format:
    I think instead of AppendLine (appending line break character) you should append html break (i.e. <br>) so that it translates correctly in HTML language when you view your email.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Stringbuilder.Appendline not working sending email

    Appendline inserts what you might remember as a 'vbcrlf' which is understood only in plaintext renderers. I'd suggest adding a "<br />" in there wherever you want a newline.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width