ASP 经典 CDO 电子邮件消息传递 - 如何隐藏电子邮件消息中的空格和换行符

发布于 2025-01-01 12:32:22 字数 580 浏览 0 评论 0原文

如何转换电子邮件中的空格和制表符。请参阅下面的示例。

test1 
test 
zzzyyy     trsthshs  asas   asas    dasdads sadasd
asdad 1    2   3   5   6  7                       8
:test only..

当我收到电子邮件时,格式已更改。数字 7 接近数字 8,间距减少到 1

test1 
test 
zzzyyy trsthshs asas asas dasdads sadasd
asdad 1 2 3 5 6 7 8
:test only..

如何保留具有多个空格的格式..

我使用了这段代码。

Set objCDOMail = Server.CreateObject("CDO.Message")
Set  objCDOMail.Configuration = cdoConfig 
objCDOMail.BodyPart.Charset = "UTF-8"
objCDOMail.HTMLBody  = sBodyText 

How can i convert space and tab in my email. kindly see below example.

test1 
test 
zzzyyy     trsthshs  asas   asas    dasdads sadasd
asdad 1    2   3   5   6  7                       8
:test only..

when i received the email the format was changed. number 7 was near to number 8, the spacing was descreased to 1

test1 
test 
zzzyyy trsthshs asas asas dasdads sadasd
asdad 1 2 3 5 6 7 8
:test only..

how can I retain the the format to have multiple spaces..

I used this code.

Set objCDOMail = Server.CreateObject("CDO.Message")
Set  objCDOMail.Configuration = cdoConfig 
objCDOMail.BodyPart.Charset = "UTF-8"
objCDOMail.HTMLBody  = sBodyText 

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

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

发布评论

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

评论(5

请远离我 2025-01-08 12:32:22

您可以使用 CDO.Message 发送消息,可以使用 .TextBody 属性以纯文本形式发送消息,也可以使用 .HtmlBody 属性以 HTML 形式发送消息,如上面的代码片段所示。如果您使用纯文本,由于在收据上典型的电子邮件阅读器中它应默认为等宽字体,因此您的手动间距将被保留。如果您需要以 HTML 形式发送,那么您需要根据 HTML 的呈现方式来格式化文本 --- 无论是电子邮件还是 Web 浏览器。您必须记住,默认情况下 HTML 会自动折叠相邻空格。因此,如果您需要格式化文本,则需要对 DIV 标记中的文本块应用正确的样式,或者可以使用 HTML PRE 标记来表示预格式化文本。

You can send a message using CDO.Message either as plaintext using the .TextBody property or as HTML using the .HtmlBody property as in your code snippet above. If you use plaintext, since it should default to a mono-spaced font in typical email reader on receipt, your manual spacing would be preserved. If you need to send as HTML, then you need to format the text according to the way HTML is rendered --- doesn't matter that it is email or in a web browser. You have to keep in mind that HTML will automatically collapse adjacent spaces by default. So if you need to format the text, you need to apply the proper styles to the block of text in a DIV tag or you can use the HTML PRE tag to denote preformatted text.

少女七分熟 2025-01-08 12:32:22

当您使用 HTML 电子邮件格式时,请在发送邮件之前尝试对邮件使用 HTML 编码。

string encodedMessage = System.Web.HttpUtility.HtmlEncode(message);

这会将邮件中的空格更改为 HTML 空格特殊字符 ( )

While you are using HTML email format, try to use HTML Encoding for the message before to send it.

string encodedMessage = System.Web.HttpUtility.HtmlEncode(message);

this will change the spaces in the mail to HTML space special character ( )

第七度阳光i 2025-01-08 12:32:22

您的文本不是 HTML,因此请勿将其分配给 HtmlBody 属性。而是使用:

objCDOMail.TextBody = sBodyText

Your text is not HTML so don't assign it to the HtmlBody property. Instead use:

objCDOMail.TextBody = sBodyText
蓝颜夕 2025-01-08 12:32:22

要替换空格、制表符、换行符,您可以执行以下操作...

    space_entity = "&" & "nbsp" & ";" 'I had to break it up like this cause stackoverflow does not take & n b s p ; sequence witohut the spaces in there ;)
    html_br = "" 'same reason! can't write regular br tag in here.. :( 

    sBodyText = replace(sBodyText," ",space_entity)
    sBodyText = replace(sBodyText,vbtab,space_entity)
    sBodyText = replace(sBodyText,vbcrlf,html_br & space_entity)

HTH

To replace, white space, tab, line feeds, you can do the following...

    space_entity = "&" & "nbsp" & ";" 'I had to break it up like this cause stackoverflow does not take & n b s p ; sequence witohut the spaces in there ;)
    html_br = "" 'same reason! can't write regular br tag in here.. :( 

    sBodyText = replace(sBodyText," ",space_entity)
    sBodyText = replace(sBodyText,vbtab,space_entity)
    sBodyText = replace(sBodyText,vbcrlf,html_br & space_entity)

HTH

愿得七秒忆 2025-01-08 12:32:22
Replace(strValue, " ", " ")
Replace(strValue, " ", " ")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文