473,385 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Strange StringBuilder behaviour when composing Email

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

<TH vAlign=top noWrap width=30><FONT face=Arial size=2 color="#ffffff"
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.
Nov 19 '05 #1
3 1405
Could you please post the code for this? It could be a logic error? I'm
interested in seeing the code first, though...

Nov 19 '05 #2
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.cdo IIS)

eMailFrom = "ab*@yahoo.com"
GetEmailBody(strBody)
eMailSubject = "testing"

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

End Sub
Nov 19 '05 #3
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.cdo IIS)

eMailFrom = "ab*@yahoo.com"
GetEmailBody(strBody)
eMailSubject = "testing"

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

End Sub
Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Google Mike | last post by:
I have RH9 and am using the PHP and MySQL that came with it. I was doing fine with all manner of my web pages for this app until I started having this very strange problem. It's a work order...
4
by: John | last post by:
Hi What are the advantages of a stringbuilder compared to a string? Thanks Regards
2
by: Paul Furman | last post by:
I don't know, maybe this isn't strange but someone else set up the shopping card coding I'm working with, the way it works is to get the time() in seconds like 1172693735 and that's the shopper_ID...
5
by: Gancy | last post by:
PROGRAM StringBuilder sbTest1 = new StringBuilder(); StringBuilder sbTest2 = new StringBuilder(); for (int i = 1; i <= 54; i++) sbTest1.Append("a");...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.