ETL*_*Man 9 delphi unicode indy
这是我的代码
电子邮件正文有一些unicode字符
LSMTP := TIdSMTP.Create(nil);
try
LMsg := TIdMessage.Create(LSMTP);
try
with LMsg do
begin
Subject := Subj;
Recipients.EMailAddresses := Email;
WriteToLog(cInformation,'To: '+Recipients.EMailAddresses);
From.Address := ReplaceVariables(From_Address);
From.Name := ReplaceVariables(From_Name);
Body.Text := EmailMessage;
ContentTransferEncoding := '8bit';
CharSet := 'UTF-8';
ContentType := 'text/plain';
end;
Run Code Online (Sandbox Code Playgroud)
这就是我得到的
Content-Type: text/plain; charset=us-ascii <<<<< WRONG
Content-Transfer-Encoding: 8bit
Date: Fri, 23 Mar 2012 17:53:19 +0000
Run Code Online (Sandbox Code Playgroud)
使用delphi 2009
Rem*_*eau 15
那是设计上的.当ContentType被设置属性,属性setter可以更新CharSet与默认值属性,如果输入不explicitally指定字符集.某些内容类型(特别是在text/领域中)具有在各种RFC中指定的特定字符集默认值.Indy尽力遵循这些规则.因此,您需要在设置CharSet属性后将属性设置为预期值ContentType,如您已发现:
//LMsg.CharSet := 'UTF-8';
LMsg.ContentType := 'text/plain';
LMsg.CharSet := 'UTF-8';
Run Code Online (Sandbox Code Playgroud)
您也可以这样做:
LMsg.ContentType := 'text/plain; charset=UTF-8';
Run Code Online (Sandbox Code Playgroud)
成功了。事件的顺序非常重要。
这个有效:
LMsg.ContentType:='text/plain';
LMsg.CharSet:='UTF-8';
Run Code Online (Sandbox Code Playgroud)
这一个不:
LMsg.CharSet:='UTF-8';
LMsg.ContentType:='text/plain';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8704 次 |
| 最近记录: |