【发布时间】:2011-11-17 16:09:02
【问题描述】:
我们希望使用 D-XE 和 Indy 的 TIdMessage 组件通过电子邮件发送以下 htm 文件作为正文:
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1253">
<meta name=Generator content="Microsoft Word 12 (filtered)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;}
.MsoChpDefault
{font-size:10.0pt;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body bgcolor=white lang=EL>
<div class=Section1>
<p class=MsoNormal><span lang=EN-US style='font-family:"Tahoma","sans-serif"'>Abcd</span><span
lang=EN-US style='font-family:"Tahoma","sans-serif"'> </span><span
style='font-family:"Tahoma","sans-serif"'>αβγδ άᾶὰἂ </span></p>
</div>
</body>
</html>
(好吧,实际文件不同但问题是一样的)。
在上述文件中,如果您将其保存为 temp.htm 并在 Internet Explorer 中加载,您将看到 4 个拉丁字符、4 个无声调的希腊字符和 4 个带声调的希腊字符(Alpha -希腊字母的第一个字母)。像这样的:
Abcd αβγδ άᾶὰἂ
到目前为止,一切都很好。
如果我们在TIdMessage 的Body 属性中加载上述文件并通过电子邮件发送它,它会显示如下:
Abcd ???? ?ᾶὰἂ
如您所见,单调字母表中的希腊字母被替换为 ???? ? - 在 WinXP 上使用 Mozilla Thunderbird 3 进行测试。
TIdMessage组件的属性如下:
我尝试将CharSet 设置为Windows-1253,但没有成功。
你有什么想法吗?
更新:
回答您的问题:
原始消息来源之后是:(电子邮件地址已编辑)
From - Thu Sep 15 11:11:06 2011
X-Account-Key: account3
X-UIDL: 00007715
X-Mozilla-Status: 0001
X-Mozilla-Status2: 00400000
X-Mozilla-Keys:
Return-Path: [redacted]
X-Envelope-To: [redacted]
X-Spam-Status: No, hits=0.0 required=5.0
tests=AWL: 0.194,BAYES_20: -0.73,HTML_MESSAGE: 0.001,
MIME_HEADER_CTYPE_ONLY: 0.56,MIME_HTML_ONLY: 0.001,MISSING_MID: 0.001,
CUSTOM_RULE_FROM: ALLOW,TOTAL_SCORE: 0.027,autolearn=no
X-Spam-Level:
Received: from localhost ([127.0.0.1])
by [redacted]
for [redacted];
Thu, 15 Sep 2011 11:10:59 +0300
From: [redacted]
Subject: Test msg
To: [redacted]
Content-Type: text/html; charset=us-ascii
Sender: [redacted]
Reply-To: [redacted]
Disposition-Notification-To: [redacted]
Return-Receipt-To: [redacted]
Date: Thu, 15 Sep 2011 11:10:59 +0300
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1253">
<meta name=Generator content="Microsoft Word 12 (filtered)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;}
.MsoChpDefault
{font-size:10.0pt;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body bgcolor=white lang=EL>
<div class=Section1>
<p class=MsoNormal><span lang=EN-US style='font-family:"Tahoma","sans-serif"'>Abcd</span><span
lang=EN-US style='font-family:"Tahoma","sans-serif"'> </span><span
style='font-family:"Tahoma","sans-serif"'>???? ?ᾶὰἂ </span></p>
</div>
</body>
</html>
Mozilla Thunderbird 也说 Message Encoding: Western (ISO-8859-1)。我尝试在 IdMessage 组件中放入不同的编码,如 windows-1253(希腊语)或 UTF-8 - 结果是一样的。此外,我尝试将 htm 文件转换为 UTF-8(使用 Notepad++) - 它看起来相同(我在 html 的 meta 信息中手动更改了字符集)。再次发送消息。结果:Abcd ???2?3?? ??ᾶὰἂ
【问题讨论】:
-
HTML 文件是否使用元标题中显示的相同编码保存?我还会尝试使用 UTF-8 并检查问题是否仍然存在于当前的 10.5.8 版本的 Indy 中。最后,我会尝试拦截(保存到文件或“调试”)传出的 SMTP 消息并检查它实际使用的编码。
-
您能在收到原始 RFC2822 消息之后发布它吗?
标签: delphi email character-encoding indy