Вот функция которая работает на XE5, на других версия не знаю... может тоже будет работать! с кодировкой всё нормально!!!
function send_mail(Hosts, Username, Password, FromAddress, FromName, RecipientsEMailAddresses, Subject, BodyMess:string;
File_List:TStringList; Ports:integer):Boolean;
var
IdSMTP1:TIdSMTP;
IdMessage1:TIdMessage;
i:integer;
begin
try
IdSMTP1:=TIdSMTP.Create(nil);
IdMessage1:=TIdMessage.Create(nil);
IdSMTP1.Host:=Hosts;
IdSMTP1.Port:=Ports;
IdSMTP1.Username:=Username;
IdSMTP1.Password:=Password;
IdSMTP1.DisConnect;
IdMessage1.Clear;
IdMessage1.From.Name := '';
SysLocale.PriLangID := LANG_RUSSIAN;
IdMessage1.CharSet := 'windows-1251';
IdMessage1.ContentType := 'multipart/related; type="multipart/alternative"';
IdMessage1.ContentTransferEncoding := '8bit';
IdSMTP1.ConnectTimeout := 60*100;
IdMessage1.Date :=now;
IdMessage1.From.Address :=FromAddress;
IdMessage1.From.Name := FromName;
IdMessage1.Recipients.EMailAddresses:=RecipientsEMailAddresses;
IdMessage1.Subject:=Subject;
with TIdText.Create(IdMessage1.MessageParts, nil) do begin
body.Add('<html><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"><b>');
body.Add('<font face="Times New Roman" size=5 color="black">'+BodyMess+'</font><br>');
body.Add('</b></html>');
ContentType := 'text/html; charset=windows-1251';
CharSet:='windows-1251';
end;
IdMessage1.IsEncoded := true;
if Trim(File_List.Text) <> '' then
begin
for i := 0 to File_List.Count - 1 do
with TIdAttachmentFile.Create(IdMessage1.MessageParts, File_List) do begin
case AnsiIndexText(ExtractFileExt(AnsiUpperCase(File_List)), ['.XLS', '.XLSX', '.RAR', '.ZIP', '.DOC', '.DOCX', '.HTML', '.TXT']) of
0: ContentType := 'application/vnd.ms-excel';
1: ContentType := 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
2: ContentType := 'application/x-rar-compres';
3: ContentType := 'application/zip';
4: ContentType := 'application/msword';
5: ContentType := 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
6: begin ContentType := 'text/html; charset=WINDOWS-1251'; {ContentDisposition := 'inline'} end;
7: begin ContentType := 'text/plain; charset=WINDOWS-1251'; {ContentDisposition := 'inline'} end;
else
ContentType := 'application/octet-stream';
end;
FileName := File_List;
end;
end;
IdSMTP1.Connect();
if IdSMTP1.Connected then begin IdSMTP1.Send(IdMessage1); result:=true; end else result:=false;
IdSMTP1.Disconnect;
finally
IdMessage1.Free;
IdSMTP1.Free;
end;
end;