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