Hallo,
Blijkt nu toch dat het probleem gerelateerd was aan mail alleen. Ik gebruik naast Delphi 10 nu ook Indy10. De problemen waren er niet met Delphi7/Indy9. Het had dus niks te maken met Windows10. Spijtig dat ik de titel van deze thread niet meer kan wijzigen..
Ik heb min of meer een oplossing gevonden:
- in vervang in de mail body de (unicode) tekens '€' door het ansi code teken € (chr(128)):
Code:
with TIdText.Create(Mess.MessageParts, nil) do
begin
TmpStr := Body_.Text;
TmpStr := StringReplace(TmpStr, '€', chr(128), [rfReplaceAll]);
Body.Text := TmpStr;
ContentType := 'text/plain';
end;
-ik zorg ervoor dat in de message 'subject' geen '€' tekens voorkomen (waar het € teken overigens goed werd getoond...).
Code:
Mess := TIdMessage.Create(nil);
try
Mess.Encoding := meMIME;
Mess.AttachmentEncoding := 'MIME';
Mess.ContentType := 'multipart/alternative';
Mess.Charset := 'iso-8859-1';
Mess.ContentTransferEncoding := '7bit';
Mess.Subject := Subject; // in Subject zijn vooraf de '€' tekens weggelaten door de aanroeper van de SendMail routine
...
Ik weet nog altijd niet waarom het goed ging met Delphi7/indy9 en niet met Delphi10/Indy10.
Zijn er meer elegante oplossingen voor dit probleem? Er is nu enkel een oplossing voor het € teken, waarbij dat teken dan nog niet mag voorkomen in het mail subject...
Dit is de volledige code van de sendmail routine (ter info):
Code:
const
ContentTypes: array[0..8] of array[0..1] of string =
(
('.txt', 'text/plain'),
('.html', 'text/html'),
('.htm', 'text/html'),
('.jpeg', 'image/jpeg'),
('.jpg', 'image/jpeg'),
('.zip', 'application/x-zip-compressed'),
('.gif', 'image/gif'),
('.png', 'image/png'),
('.rar', 'application/x-rar-compressed')
);
function SendMail(Subject, Towards: string; Body_: TStrings;
CC: string = ''; BCC: string = ''; Attachments: TStrings = nil): Boolean;
var
Mess: TIdMessage;
IdSMTP1: TIdSMTP;
idSASLLogin: TIdSASLLogin;
idUserPassProvider: TIdUserPassProvider;
I, J: Integer;
Ext_: string;
TmpStr: String;
begin
Result := false;
IdSMTP1 := TIdSMTP.Create(nil);
try
IdSMTP1.host := SMTPHost;
IdSMTP1.port := strtoint(SMTPPort);
IdSMTP1.AuthType := SMTPAuth;
IdSMTP1.Username := SMTPId;
IdSMTP1.Password := SMTPPw;
IdSMTP1.MailAgent := 'Indy 10';
IdSMTP1.ReadTimeout := 60000;
//IdSMTP1.UseTLS := utUseExplicitTLS;
if strtoint(SMTPPort) <> 25 then
begin
idSMTP1.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(idSMTP1);
idSMTP1.UseTLS := utUseExplicitTLS;
TIdSSLIOHandlerSocketOpenSSL(idSMTP1.IOHandler).SSLOptions.Method := sslvSSLv23;
idSASLLogin := TIdSASLLogin.Create(idSMTP1);
idUserPassProvider := TIdUserPassProvider.Create(idSASLLogin);
idSASLLogin.UserPassProvider := idUserPassProvider;
idUserPassProvider.Username := SmtpId;
idUserPassProvider.Password := SmtpPW;
idSMTP1.AuthType := satDefault;
idSMTP1.SASLMechanisms.Add.SASL := idSASLLogin;
end;
Mess := TIdMessage.Create(nil);
try
Mess.Encoding := meMIME;
Mess.AttachmentEncoding := 'MIME';
Mess.ContentType := 'multipart/alternative';
Mess.Charset := 'iso-8859-1';
Mess.ContentTransferEncoding := '7bit';
Mess.Subject := Subject;
Mess.Recipients.Emailaddresses := Towards; // comma separated addresses
Mess.CCList.EMailAddresses := CC; // comma separated addresses
Mess.BCCList.EMailAddresses := BCC; // comma separated addresses
Mess.from.Address := SMTPFrom;
Mess.ReplyTo.Emailaddresses := SMTPAnswer; // comma separated addresses
if not Assigned(Attachments) then // no attachments
begin
with TIdText.Create(Mess.MessageParts, nil) do
begin
TmpStr := Body_.Text;
TmpStr := StringReplace(TmpStr, '€', chr(128), [rfReplaceAll]);
Body.Text := TmpStr;
ContentType := 'text/plain';
end;
end
else // attachments present
begin
// Add a blank TIdText with its ContentType property set to multipart/alternative
with TIdText.Create(mess.MessageParts, nil) do
begin
ContentType := 'multipart/alternative';
// Leave the ParentPart properties set to -1
end;
// Add TIdText instances for the plain-text and HTML contents. Set the ParentPart properties to the index of the multipart/altrnative part.
with TIdText.Create(Mess.MessageParts, nil) do
begin
TmpStr := Body_.Text;
TmpStr := StringReplace(TmpStr, '€', chr(128), [rfReplaceAll]);
Body.Text := TmpStr;
ContentType := 'text/plain';
ParentPart := 0;
end;
for I := 0 to Attachments.Count - 1 do
begin
if FileExists(Attachments[I]) then
begin
with TIdAttachmentFile.Create(Mess.MessageParts, Attachments[I]) do
begin
ContentType := 'application/octet-stream'; // default (binary) contenttype
// find out the actual contenttype
Ext_ := ExtractFileExt(Attachments[I]);
for J := 0 to High(ContentTypes) do
begin
if Uppercase(Ext_) = Uppercase(ContentTypes[J, 0]) then
begin
ContentType := ContentTypes[J, 1];
break;
end;
end;
FileName := ExtractFileName(Attachments[I]);
end;
end;
end;
Mess.ContentType := 'multipart/mixed';
end;
try
IdSMTP1.Connect;
try
IdSMTP1.Send(Mess);
Result := true; // success
finally
IdSMTP1.Disconnect;
end;
except
on Exception do ; // failiure
end;
finally
Mess.Free;
end;
finally
IdSMTP1.Free;
end;
end;
Bookmarks