String Variable not formatted in HTML Email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Asprisa
    New Member
    • Oct 2007
    • 30

    String Variable not formatted in HTML Email

    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:
    Code:
    mail.IsBodyHtml = True
    mail.Body = "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""> " &
    "<html xmlns=""http://www.w3.org/1999/xhtml"">" &
    "<head>" &
    "<style type=""text/css"">" &
    "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;}" &
    "</style>" &
    "</head> " &
    "<body>" &
    "<p>--------------------------------------------------------------</p>" &
    "<p></p>" &
    description &
    "<p></p>" &
    "<p>--------------------------------------------------------------</p>" &
    "</body>" &
    "</html>"
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I'm not entirely sure what you're having problems with by try this.


    Code:
    mail.IsBodyHtml = True
    
    Dim theBody As New Text.StringBuilder
    
    theBody.AppendLine("<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""> ")
    theBody.AppendLine("<html xmlns=""http://www.w3.org/1999/xhtml"">")
    theBody.AppendLine("<head>")
    theBody.AppendLine("<style type=""text/css"">")
    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;}")
    theBody.AppendLine("</style>")
    theBody.AppendLine("</head> ")
    theBody.AppendLine("<body>")
    theBody.AppendLine(<p>--------------------------------------------------------------</p>")
    theBody.AppendLine("<p></p>")
    theBody.AppendLine(description)
    theBody.AppendLine("<p></p>")
    theBody.AppendLine("<p>--------------------------------------------------------------</p>")
    theBody.AppendLine("</body>")
    theBody.AppendLine("</html>")
    
    
    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

    Comment

    • Asprisa
      New Member
      • Oct 2007
      • 30

      #3
      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:

      Code:
      theBody.AppendLine("<p>")
      
      Using SR = New IO.StringReader(description)
      
      While SR.Peek >= 0
      
      Dim l As String = SR.ReadLine()
      
      theBody.AppendLine(l & "<br />")
      
      End While
      
      End Using
      
      theBody.AppendLine("</p>")
      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.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I'm glad you solved the problem :)

        -Frinny

        Comment

        Working...