Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spaces appearing in HTMLBody when sent through email 1

Status
Not open for further replies.

ranta

Programmer
Jun 24, 2003
30
Hi,

I am currently sending a HTML newsletter from an ASP application using the script below. I have used this in many applications with no issue however I am now facing a problem that when the HTML content (which I have validated by printing to the screen) is sent using the .send command a random space is appears right in the middle of a <br /> statement, this space appears between the b and the r and the email clients then render this as a <b> and embolden all content after the tag.

The random spaces always appears in the same place and is not there just prior to the .send command. Is there a possibility that using the CDO.message method has a character limit and it actualy trys to create line breaks or split the email into packets therefore generating this space?

Any assitance would be greatly appreciated as I am pulling my hair out here... Thanks!

Dim iMsg,iConf

On Error Resume next
Server.ScriptTimeout = 9000
If emailto<>"" And emailFRom<>"" Then

Set iMsg = CreateObject("CDO.Message")
Set iConf = iMsg.Configuration

'Set the fields of the configuration object to send by using SMTP through port 25.
With iConf.Fields
.item(" = cdoSendUsingPort
.item(" = strSmartHost
.Update
End With

With iMsg
.To = emailTo
.From = emailFrom
.Subject = subject
If CC <> "" Then
.cc=cc
End If
If BCC <> "" Then
.bcc=bcc
End If
If html = 2 Then
.HTMLBody = body
.TextBody = body
Elseif html = 1 then
.HTMLBody = body
else
.TextBody = body
End if
If attachment <> "" Then
.AddAttachment attachment
End if
.Send
End With
set iMsg = Nothing

If Err.Number = "" Or Err.Number="0" Then

sendEmail = 1
Else
sendEmail = Err.number
End if
Else
sendEmail = -1
End If
 
Chris,

Thanks for the response. I am a little surprised that we haven't come across this issue before. Even looking at the email in question there are huge chunks of HTML content which span more than 76 characters and don't seem to be forced to break lines. Do you have any understanding as to why this would only cause certain lines to break in this manner?|

What is the general approach to solving this problem, do you actualy have to re-format the entire email adding line breaks before 76 characters are reached (somthing which would need a comprehensive regular expression to ensure HTML tags were not curropted etc)?

Many thanks,
Rory
 
HTML content ignores whitespace > 1, linebreaks and CRs.
Only when you "break" some tags across two lines can problems occur, other tags will "break" with no ill effects at all.
Never done any research to find which are affected though.

I simply add a vbCrLf to the end tags and <br>'s before firing off the email.

LineBreak function
Code:
Private Function LineBreak(ByVal strIn As String)
Dim objRE As RegExp
Dim objREMatches As MatchCollection
Dim objMatch As Match

Set objRE = New RegExp
objRE.IgnoreCase = True
objRE.Global = True
objRE.Pattern = "(</[a-z]*>)|<br>|<[a-z\s]*/>"
Set objREMatches = objRE.Execute(strIn)
For Each objMatch In objREMatches
strIn = Replace(strIn, objMatch, objMatch + vbCrLf)
Next
LineBreak = strIn
End Function

Make sure you add a reference to "Microsoft VBScript Regular Expressions 5.5" to the project first.




Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top