Здравствуйте, lsv, Вы писали:
lsv>Отправляю письмо с помощью TIdSMTP и TIdMessage, работаю с Indy10 в CodeGear C++Builder.
lsv>lsv> IdSMTP = new TIdSMTP(NULL);
lsv> IdSMTP->AuthType = satDefault;
lsv>...
lsv> Msg = new TIdMessage(NULL);
Msg->>ContentType = L"text/plain; charset=koi8-r";
Msg->>IsEncoded = true;
Msg->>Encoding = meMIME;
Msg->>ContentTransferEncoding = L"8bit";
Msg->>Body->Text = L"Тело сообщения";
lsv>...
lsv> IdSMTP->Connect();
lsv> IdSMTP->Send(Msg);
lsv>
lsv>Когда письмо приходит то оно состоит из знаков вопроса
lsv>???? ?????????
lsv>В чем может быть проблема, что еще надо включить или поменять, а то уже мозг сломал?
Когда-то похожее я находил на Delphi Kingdom — там часто возникают вопросы по Indy. Вот привожу код:
uses IdMessage,
IdAttachmentFile,
IdText,
IdSMTP,
IdPOP3,
IdCoderHeader,
...
Procedure TMailer.LInitializeISO(Sender: TObject; var VTransferHeader: TTransfer;
var VHeaderEncoding: Char; var VCharSet: string);
begin
VTransferHeader:=bit8;
VHeaderEncoding:='B';
VCharSet:='Windows-1251';
end;
function TMailer.SendMail(const Host,Password,Username: String;
const Recipients: array of String;
const FromAdres,Subject: String;
const MessageText: String;
const Attachments: array of String): boolean;
var EMsg: TIdMessage;
IdSMTP1: TIdSMTP;
EText: TIdText;
i: integer;
begin
result := false;
IdSMTP1 := TIdSMTP.Create(nil);
IdSMTP1.Host:= Host;
IdSMTP1.Password:= Password;
IdSMTP1.Username:= Username;
EMsg := TIdMessage.Create(IdSMTP1);
EMsg.OnInitializeISO := Self.LInitializeISO;
try
EMsg.CharSet := 'Windows-1251';
EMsg.Subject := Subject;
EMsg.ContentTransferEncoding := '8bit';
EText := TIdText.Create(EMsg.MessageParts);
EText.Body.Text :=
'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'+
'<html><head>'+
'<meta http-equiv="content-type" content="text/html; charset=Windows-1251">'+
'<title>Тра-ля-ля </title></head>'+
'<body bgcolor="#ffffff">'+
MessageText + '</body></html>';
EText.ContentType := 'text/html';
EText.CharSet := 'Windows-1251';
EText.ContentTransfer := '8bit';
for i := 0 to high(Recipients) do
EMsg.Recipients.Add.Address :=Recipients[i];
EMsg.From.Address := FromAdres;
EMsg.Body.Clear;
EMsg.Date := now;
for i := 0 to high(Attachments) do
if FileExists(Trim(Attachments[i])) then
TIdAttachmentFile.Create(EMsg.MessageParts, Attachments[i]);
EMsg.AfterConstruction;
IdSMTP1.Connect;
if IdSMTP1.Connected
then
try
IdSMTP1.Send(EMsg);
result := true;
except
end;
finally
IdSMTP1.Disconnect;
EMsg.Free;
end;
end;
Кстати, а для koi8-r можно попробовать еще такое:
Procedure TMailer.LInitializeISO(Sender: TObject; var VTransferHeader: TTransfer;
var VHeaderEncoding: Char; var VCharSet: string);
begin
VTransferHeader:=bit7;
VHeaderEncoding:='Q';
VCharSet:='koi8-r';
end;