PDA

View Full Version : asp email sending .HTMLBody string breaking up - causing table corruption


yaggy85
02-03-2009, 11:40 PM
Hi guys. i have a simple email script, which works. im running into the following problem:

When i send the email to outlook 2003, sometimes because the HTMLBody string is so long, the html gets broken up into 4 long lines. i can see it in 4 long lines when i "view source" in outlook 2003 in the email body.

then this happens:

the email body source has this at the end of the first line of code: ...</td></tr><tr><t

then on the next line is starts with: d height="23" width="203">

because of this code breaking up, some of the tables are all messed up. because there are server variables being requested from a database, sometimes the table doesn't get messed up because it will break the code up at different spots along the string, depending on how many characters the variable is, etc. so if the store name is "thislong" for example, it may break the string up at the wrong spot (where my table gets corrupted) but if the store name is "thisthislong", it might be fine and break the script up at a place that won't corrupt the html output.

So i was wondering if there's a way, to tell my email script when to start a new line, or where to break my code, so i can choose to break it somewhere where it will not corrupt my tables or anything?

?

thanks in advance

here is the code btw..


CONST SMTPServer = "localhost"
' only required for CDO.Message method:
CONST cdoURL = "http://schemas.microsoft.com/cdo/configuration/"

CONST FromAddress = "pryon@com1.com.au"
CONST FromName = "COM1 International"
CONST ToAddress = "test"
CONST ToName = "Their Name"
CONST Subject = "RA"
CONST url = "http://www.pryon.com.au/"
htmlbody = "nothing"
textbody = "You need HTML email"

' for CDO.Message:

set cdoM = CreateObject("CDO.Message")
set cdoC = CreateObject("CDO.Configuration")

Set cdoF = cdoC.Fields
With cdoF
.Item(cdoURL & "sendusing") = 2
.Item(cdoURL & "smtpserver") = SMTPServer
.Item(cdoURL & "smtpconnectiontimeout") = 10
.Update
End With

With cdoM
Set .Configuration = cdoC
.From = FromAddress
.To = request.form("copyemail")
.Subject = "RA #" & rs("requesttype") & "" & rs("ID") & ""
.HTMLBody = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=windows-1252'></head><body><div align='center'><table border='1' width='600' id='table1' bordercolorlight='#000000' bordercolordark='#000000' style='border-collapse: collapse' cellpadding='5'><tr><td height='26' valign='bottom' colspan='3' width='444'><div align='center'><p class='MsoNormal' align='left'><b><span style='font-size: 15.0pt; font-family: Tahoma'>&nbsp;<img border='0' src='http://www.yagz.com/com_1/images/header.gif' width='170' height='59'>&nbsp;</span><br><i><span style='font-family: Tahoma'><font size='3'>&nbsp; Harvey Norman Return Authorisation Form V1.5</font></span></i></b></p></div></td></tr><tr><td height='34' width='203'><u><b><font face='Trebuchet MS' size='2'>Contact Details</font></b></u></td><td width='475' colspan='2'>&nbsp;</td></tr><tr><td valign='top' height='25' width='203'><font face='Trebuchet MS' size='2'>Store Name:</font></td><td valign='top' width='475' colspan='2'><i><font face='Trebuchet MS' size='2'>&nbsp;&nbsp;" & RS.Fields("storename") & "</font></i></td></tr><tr><td height='23' width='203'> <font face='Trebuchet MS' size='2'>Store Phone Number:</font></td><td valign='top' width='475' colspan='2'><i><font face='Trebuchet MS' size='2'>&nbsp;&nbsp;" & RS.Fields("storephone") & "</font></i></td></tr><tr><td height='30' valign='top' width='203'><font face='Trebuchet MS' size='2'>Store Email Address:</font></td><td valign='top' width='475' colspan='2'><i><font face='Trebuchet MS' size='2'>&nbsp;&nbsp;" & RS.Fields("storeemail") & "</font></i></td></tr><tr><td height='20' width='203'><font face='Trebuchet MS' size='2'>Primary Contact Name:</font></td><td width='475' colspan='2'><i><font face='Trebuchet MS' size='2'>&nbsp;&nbsp;" & RS.Fields("contactname") & "</font></i></td></tr><tr><td valign='top' height='31' width='203'><font face='Trebuchet MS' size='2'>Alternate Contact Name:</font></td><td valign='top' width='475' colspan='2'><i><font face='Trebuchet MS' size='2'>&nbsp;&nbsp;" & RS.Fields("altcontactname") & "</font></i></td></tr><tr><td height='21' width='203'><u><b><font face='Trebuchet MS' size='2'>Claim Details</font></b></u></td><td valign='top' width='475' colspan='2'>&nbsp;</td></tr><tr><td valign='top' height='25' width='203'><font face='Trebuchet MS' size='2'>Type Of Request:</font></td><td valign='top' width='46'><i><font face='Trebuchet MS' size='2'>&nbsp;&nbsp;<b>" & RS.Fields("requesttype") & "</b></font></i></td><td valign='top' width='417'><i><font face='Trebuchet MS' size='1'>&nbsp;&nbsp;&nbsp;&nbsp;( <b>R</b> = Repair,&nbsp; <b>C</b> = Credit,&nbsp; <b>A</b> = Advanced Replacement )</font></i></td></tr><tr><td height='22' width='203'><u><b><font face='Trebuchet MS' size='2'>Product Details</font></b></u></td><td valign='top' width='475' height='22' colspan='2'>&nbsp;</td></tr><tr><td height='26' width='203'><font face='Trebuchet MS' size='2'>COM1 Invoice Number:</font></td><td valign='top' width='475' colspan='2'><i><font face='Trebuchet MS' size='2'>&nbsp;&nbsp;" & RS.Fields("invoice") & "</font></i></td></tr><tr><td height='30' valign='top' width='203'><font face='Trebuchet MS' size='2'>Model:</font></td><td valign='top' width='475' colspan='2'><i><font face='Trebuchet MS' size='2'>&nbsp;&nbsp;" & RS.Fields("productcode") & "</font></i></td></tr><tr><td height='36' width='203'><font face='Trebuchet MS' size='2'>Product Serial Number:</font></td><td valign='top' width='475' colspan='2'><i><font face='Trebuchet MS' size='2'>&nbsp;&nbsp;" & RS.Fields("serialnumber") & "</font></i></td></tr><tr><td height='42' valign='top' width='203'><font face='Trebuchet MS' size='2'>Fault Description:</font><p>&nbsp;</p><p>&nbsp;</p></td><td valign='top' width='475' colspan='2'><i><font face='Trebuchet MS' size='1'>&nbsp;&nbsp;" & RS.Fields("fault") & "</font></i></td></tr><tr><td valign='top' height='26' width='203'><u><b><font face='Trebuchet MS' size='2'>RA#</font></b></u></td><td valign='top' width='475' colspan='2'><i><font face='Trebuchet MS' size='2'>&nbsp;&nbsp;" & RS.Fields("requesttype") & " " & RS.Fields("ID") & "</font></i></td></tr><tr><td height='22' width='203'><u><b><font face='Trebuchet MS' size='2'>Date Of Issue</font></b></u></td><td valign='top' width='475' colspan='2'><i><font face='Trebuchet MS' size='2'>&nbsp;&nbsp;" & todaysDate & "</font></i></td></tr></table></div></body></html>"

' alternate for non-HTML-aware:

.TextBody = textbody
.Send
End With

Set cdoM = Nothing
Set cdoS = Nothing
Set cdoF = Nothing

TheShaner
02-04-2009, 03:56 AM
All you need to do is break up your long string with the vbCrLf control charcter like so:
.HTMLBody = "<table><tr>" & vbCrLF & "<td>Data</td>" & vbCrLF & "</tr></table>"
Your source code will then look like:
<table><tr>
<td>Data</td>
</tr></table>
What vbCrLf does is force the code after it to start on a new line. You can put this anywhere it makes sense to break up your source code. This will then prevent Outlook from inserting its own new line characters in the source code and breaking up your table structure.

-Shane