By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

String Variable not formatted in HTML Email

P: 30
Hi Guys,

Been racking my brain most of the afternoon on this one, if anyone can shed any light, i would really appriciate it.

Basically I am pulling the body of an email out as text not HTML into a variable called Description (string), if i show the variable in a msgbox it is formatted in terms of line breaks etc.

I then add the description variable to a line in an HTML formatted email, the email is perfect except the Description variable which has no line breaks etc, so it all appears on one line.

Any thoughts?

Here's the HTML code:
Expand|Select|Wrap|Line Numbers
  1. mail.IsBodyHtml = True
  2. mail.Body = "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""> " &
  3. "<html xmlns=""http://www.w3.org/1999/xhtml"">" &
  4. "<head>" &
  5. "<style type=""text/css"">" &
  6. "body {background-color:ffffff;background-image:url(http://);background-repeat:no-repeat;background-position:top left;background-attachment:fixed;text-align:left;font-family:Garamond;font-size:14px;font-style:normal;font-weight:550;color:000000;}" &
  7. "</style>" &
  8. "</head> " &
  9. "<body>" &
  10. "<p>--------------------------------------------------------------</p>" &
  11. "<p></p>" &
  12. description &
  13. "<p></p>" &
  14. "<p>--------------------------------------------------------------</p>" &
  15. "</body>" &
  16. "</html>"
Dec 4 '12 #1
Share this Question
Share on Google+
3 Replies


Frinavale
Expert Mod 5K+
P: 9,731
I'm not entirely sure what you're having problems with by try this.


Expand|Select|Wrap|Line Numbers
  1. mail.IsBodyHtml = True
  2.  
  3. Dim theBody As New Text.StringBuilder
  4.  
  5. theBody.AppendLine("<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""> ")
  6. theBody.AppendLine("<html xmlns=""http://www.w3.org/1999/xhtml"">")
  7. theBody.AppendLine("<head>")
  8. theBody.AppendLine("<style type=""text/css"">")
  9. theBody.AppendLine("body {background-color:ffffff;background-image:url(http://);background-repeat:no-repeat;background-position:top left;background-attachment:fixed;text-align:left;font-family:Garamond;font-size:14px;font-style:normal;font-weight:550;color:000000;}")
  10. theBody.AppendLine("</style>")
  11. theBody.AppendLine("</head> ")
  12. theBody.AppendLine("<body>")
  13. theBody.AppendLine(<p>--------------------------------------------------------------</p>")
  14. theBody.AppendLine("<p></p>")
  15. theBody.AppendLine(description)
  16. theBody.AppendLine("<p></p>")
  17. theBody.AppendLine("<p>--------------------------------------------------------------</p>")
  18. theBody.AppendLine("</body>")
  19. theBody.AppendLine("</html>")
  20.  
  21.  
  22. mail.Body = theBody.ToString
Edit:
I just re-read your question.
You need to post the code populates the description variable. Did you put line breaks in it?


-Frinny
Dec 4 '12 #2

P: 30
Hi Frinny,

Thanks for the reply, I was doing some thinking last night and managed to come up with the answer this morning.

It goes along the lines you were thinking at the bottom of your post:

Expand|Select|Wrap|Line Numbers
  1. theBody.AppendLine("<p>")
  2.  
  3. Using SR = New IO.StringReader(description)
  4.  
  5. While SR.Peek >= 0
  6.  
  7. Dim l As String = SR.ReadLine()
  8.  
  9. theBody.AppendLine(l & "<br />")
  10.  
  11. End While
  12.  
  13. End Using
  14.  
  15. theBody.AppendLine("</p>")
  16.  
  17.  
This code was able to strip each line out of the string, and then i simply put the HTML formatting around the output.

Thanks for your help!

James.
Dec 5 '12 #3

Frinavale
Expert Mod 5K+
P: 9,731
I'm glad you solved the problem :)

-Frinny
Dec 5 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.