使用 CDO 在电子邮件正文中随机感叹号

发布于 2024-08-19 17:04:38 字数 777 浏览 4 评论 0原文

我们在经典 ASP 中使用 CDO 对象在电子邮件正文中收到随机感叹号 (!) 标记。

我们在 Outlook 中没有看到这个感叹号。问题仅发生在 Lotus Notes 客户端上。我们使用 IIS SMTP 服务器来发送电子邮件。

编辑

Set myMail= Server.CreateObject("CDO.Message")
myMail.Subject="Business and Company News on your Mobile Device"
myMail.From="[email protected]"
myMail.To="[email protected]"
htmlbody = htmlbody (coming runtime)
myMail.BodyPart.ContentTransferEncoding = "quoted-printable"
myMail.HTMLBody = htmlbody
myMail.Send

我认为客户端没有使用 SMTP。但他们肯定正在使用 LotusNotes。

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.Subject="Business and Company News on your Mobile Device"
myMail.From="[email protected]"
myMail.To="[email protected]"
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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

雅心素梦 2024-08-26 17:04:39

电子邮件中的感叹号通常是由于行太长造成的。将您在 ASP 中创建的电子邮件正文转储到文件中并检查它。尝试在合理的地方用换行符分割行。我假设这是一条 HTML 消息 - 将换行符放在适当的 HTML 标记后面。

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.

無處可尋 2024-08-26 17:04:39

我在代码中看到的唯一区别是

 .HTMLBody= psBody
 .HTMLBodyPart.ContentTransferEncoding = "quoted-printable"

So HTMLBodyPart.... 而不是 BodyPart.....

不知道这是否有区别,但您可以尝试一下。

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.

难理解 2024-08-26 17:04:39

如果我没记错的话,“quoted-printable”解决方案可以工作,但它会产生二进制附件的问题。因此,我编写了一个小的 VbScript 函数来修复长字符串并使 htmlbody 与所有客户端兼容。这里是:

<%
'
' **** 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>")
%>

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>")
%>
睫毛溺水了 2024-08-26 17:04:39

我发现的最好的解决方案是使用这段代码:

ObjMail.HtmlBody="text of your message"
'*** NOTE: the following instruction has to be placed HERE, just after the HtmlBody
ObjMail.HtmlBodyPart.ContentTransferEncoding = "quoted-printable"

它似乎工作完美!

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!

秋心╮凉 2024-08-26 17:04:39

当每行超过 750 个字符时就会发生这种情况。尝试使用 vbNewLine 或 Chr(10) 在 html 中分割行。

例子:

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>"

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>"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文