Random exclamation mark in email body using CDO
We are getting random exclamation (!) mark in email body using CDO object in Classic ASP.
We are not getting this exclamation mark with outlook. Problem only occur with Lotus Notes client. We use IIS SMTP server to send email.
Edit
Set myMail= Server.CreateObject("CDO.Message")
myMail.Sub开发者_高级运维ject="Business and Company News on your Mobile Device"
myMail.From="no-reply@test.com"
myMail.To="some@email.com"
htmlbody = htmlbody (coming runtime)
myMail.BodyPart.ContentTransferEncoding = "quoted-printable"
myMail.HTMLBody = htmlbody
myMail.Send
I think client is not using SMTP. But they are using LotusNotes for sure.
Exclamation marks in emails are usually caused by lines being too long. Dump the email body you're creating in ASP to a file and examine it. Try to split lines at sensible places with newlines. I assume this is a HTML message - place newlines after appropriate HTML tags.
Only difference I see with my code is
.HTMLBody= psBody
.HTMLBodyPart.ContentTransferEncoding = "quoted-printable"
So HTMLBodyPart....
in stead of BodyPart.....
Don't know if that makes a difference, but you can try it.
If I'm not wrong, the "quoted-printable" solution works but it generates problems with binary attachments. So I wrote a little VbScript function that fixes long strings and makes the htmlbody compatible with all clients. Here it is:
<%
'
' **** fix CDOSYS exclamation mark problem - TFI 10/22/2013 - v1.1
'
' This function breaks a string into 76 chars (or less) lines, thus avoiding
' the "exclamation mark" problem when sending e-mails through CDOSYS component
' v.1.1 - fixed a bug that clipped the message at its end
function fixstring(string1)
Dim string2,pstart,pos0,pos1,part
string2=""
pstart=1
do
part=mid(string1,pstart,76)
pos0=instr(part,vbcrlf)
if pos0=0 then
pos1=instrrev(part," ")
if pos1=0 then
string2=string2&part&vbcrlf
pstart=pstart+76
else
string2=string2&left(part,pos1)&vbcrlf
pstart=pstart+pos1
end if
else
string2=string2&left(part,pos0)&vbcrlf
pstart=pstart+pos0
end if
loop while pstart<len(string1)
fixstring=string2
end function
string1="Lorem ipsum dolor sit"&vbcrlf&"amet, consectetur adipiscing elit. Sed in dignissim risus. Vestibulum ac justo sed massa posuere pellentesque non et odio. Suspendisse scelerisque sed ante in ullamcorper. Sed vel diam sed ligula commodo aliquet. Fusce aliquam eleifend arcu, vitae euismod purus pellentesque ac. In adipiscing, eros a semper semper, magna ligula volutpat dui, a vulputate nisl tellus a nisi. Donec et fringilla tellus. Praesent nibh neque, hendrerit ut fringilla eget, condimentum nec ligula. Mauris porta et velit et faucibus. Morbi aliquam risus urna, eu ultricies purus venenatis eget. Donec elementum ante dictum, euismod augue at, euismod lorem. Praesent sit amet tempus est. Nam et neque mollis, pretium ante sed, aliquet enim. abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrs Integer vestibulum lacus euismod lectus placerat, ut commodo metus tempor. Vivamus sagittis mauris id fringilla mattis. Nam convallis accumsan nulla nec eleifend. Suspendisse lobortis iaculis magna vel convallis. Ut id metus posuere, ullamcorper sapien at, sodales massa. Aenean commodo quis dolor vitae convallis. Duis sed metus non nisl commodo porttitor a sed augue. Vestibulum non risus bibendum, aliquam nulla vel, imperdiet sem. Suspendisse mattis eu lorem ac accumsan. Donec eget pulvinar libero. Nam cursus gravida gravida. Proin interdum elementum euismod. Nunc nec viverra ipsum. Nunc ultrices purus nisi, sed scelerisque elit suscipit ut. "
response.write "<b>string1:</b><br>"&string1&"<BR><br>"
response.write "<b>string2:</b><br>"&replace(fixstring(string1),vbcrlf,"<br>")
%>
The best solution I found is to use this code:
ObjMail.HtmlBody="text of your message"
'*** NOTE: the following instruction has to be placed HERE, just after the HtmlBody
ObjMail.HtmlBodyPart.ContentTransferEncoding = "quoted-printable"
It seems to work flawlessly!
This happens when there are over 750 characters per line. Try use vbNewLine or Chr(10) to split lines in html.
Example:
Set rs = conn.execute(txtsql)
html = ""
html = html & "<h1>Hi " & rs("Engineer_Name") & "</h1>" & vbNewLine
html = html & "<div class=''><table class='maintable'>" & vbNewLine
html = html & "<thead>"
html = html & "<tr>"
html = html & "<th>ID</th>"
html = html & "<th>Title</th>"
html = html & "</tr>"
html = html & "</thead>" & vbNewLine
html = html & "<tbody>" & vbNewLine
Do Until rs.EOF
html = html & "<tr>"
html = html & "<td>" & rs("ID_Calendar") & "</td>"
html = html & "<td>" & rs("Title") & "</td>"
html = html & "</tr>" & vbNewLine
rs.movenext
Loop
html = html & "</tbody>" & vbNewLine
html = html & "</table></div>"
精彩评论