Strange StringBuilder behaviour when composing Email

G

Guest

Hi

I am using StringBuilder to compose an email. The body of email consists of
a table for which data has to be taken fron SQL Server.

I use append method to add text to the StringBuilder variable. When I am
finished I call ToString function to get the string.

The problem is that many times, it changes the text I appended to it. Like
when I appended

ABC<BR>6<BR>5<BR>05</FONT></TH>

it changed to

<TH vAlign=top noWrap width=30><FONT face=Arial size=2 r="#ffffff"
colo>ABC<BR>6<BR>5<BR>05</FONT></TH>

I tried using the String instead of StringBuilder but the problem is still
there.

Please help me.
 
S

Seraph

Could you please post the code for this? It could be a logic error? I'm
interested in seeing the code first, though...
 
G

Guest

here is simplified version of my code

Public Sub GetEmailBody(ByRef strHTMLMessage As StringBuilder)

Dim strQuery As String
Dim Adodc1 As ADODB.Recordset
strHTMLMessage.Remove(0, strHTMLMessage.Length)

' create HTML message
strHTMLMessage.Append("<html><head><title>My page</title> " _
& "<style type=""text/css"">th {color:
#ffffff;font: bold 12px arial} td.b {color: #ffffff;font: bold 12px arial}
</style></head><body>" _
& "<table align=center border=1 cellspacing=0
cellpadding=1 style='border-collapse: collapse' bordercolor=#777777>" _
& "<tr bgcolor=#ff0000>" _
& "<th nowrap valign=top align=left
width=200>col1</th>" _
& "<th valign=top>col2</th>" _
& "<th nowrap valign=top>col3<br>one<br>two</th>" _

Adodc1 = New ADODB.Recordset


Dim strQuery As String = "SELECT * FROM sample"

' conn is global Adodb.Connection
Adodc1.Open(strQuery, conn)

If Not Adodc1.EOF Then

Do Until Adodc1.EOF

strHTMLMessage.Append(vbCrLf & "<tr bgcolor=#ffcccc>")

strHTMLMessage.Append("<td nowrap align=left>" &
tmpPlay.StationName & "</td><td nowrap align=left>" &
tmpPlay.PresentationRegion & "</td>")

loop

strHTMLMessage.Append("</tr>")

Next

' end of table
strHTMLMessage.Append("</table>")
strHTMLMessage.Append("</body></html>")

End Sub

Public Sub SendEmail()

Dim strBody As New StringBuilder

Dim mailmsg As CDO.Message
Dim Conf As CDO.Configuration
mailmsg = New CDO.Message
mailmsg.Configuration.Load(CDO.CdoConfigSource.cdoIIS)

eMailFrom = "(e-mail address removed)"


GetEmailBody(strBody)
eMailSubject = "testing"

With mailmsg
.From = eMailFrom
.Subject = eMailSubject
.To = recp(i).email
.HTMLBody = strBody.ToString
.Send()
End With

End Sub
 
G

Guest

Public Sub GetEmailBody(ByRef strHTMLMessage As StringBuilder)

Dim strQuery As String
Dim Adodc1 As ADODB.Recordset
strHTMLMessage.Remove(0, strHTMLMessage.Length)

' create HTML message
strHTMLMessage.Append("<html><head><title>My page</title> " _
& "<style type=""text/css"">th {color:
#ffffff;font: bold 12px arial} td.b {color: #ffffff;font: bold 12px arial}
</style></head><body>" _
& "<table align=center border=1 cellspacing=0
cellpadding=1 style='border-collapse: collapse' bordercolor=#777777>" _
& "<tr bgcolor=#ff0000>" _
& "<th nowrap valign=top align=left
width=200>col1</th>" _
& "<th valign=top>col2</th>" _
& "<th nowrap valign=top>col3<br>one<br>two</th>" _

Adodc1 = New ADODB.Recordset


Dim strQuery As String = "SELECT * FROM sample"

' conn is global Adodb.Connection
Adodc1.Open(strQuery, conn)

If Not Adodc1.EOF Then

Do Until Adodc1.EOF

strHTMLMessage.Append(vbCrLf & "<tr bgcolor=#ffcccc>")

strHTMLMessage.Append("<td nowrap align=left>" &
tmpPlay.StationName & "</td><td nowrap align=left>" &
tmpPlay.PresentationRegion & "</td>")

loop

strHTMLMessage.Append("</tr>")

Next

' end of table
strHTMLMessage.Append("</table>")
strHTMLMessage.Append("</body></html>")

End Sub

Public Sub SendEmail()

Dim strBody As New StringBuilder

Dim mailmsg As CDO.Message
Dim Conf As CDO.Configuration
mailmsg = New CDO.Message
mailmsg.Configuration.Load(CDO.CdoConfigSource.cdoIIS)

eMailFrom = "(e-mail address removed)"


GetEmailBody(strBody)
eMailSubject = "testing"

With mailmsg
.From = eMailFrom
.Subject = eMailSubject
.To = recp(i).email
.HTMLBody = strBody.ToString
.Send()
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top