Results 1 to 9 of 9

Thread: € teken in Deplhi 10 applicatie in windows 10 getoond als ?

  1. #1

    € teken in Deplhi 10 applicatie in windows 10 getoond als ?

    Hallo,

    Ik heb een paar applicaties ontwikkeld, en een de gebruikers zegt dat het euro teken (€) getoond wordt als een vraagteken op zijn PC.
    Ikzelf draai Windows10 ook (in een virtuele machine) en ik heb geen probleem.

    Iemand enig idee?
    Alvast bedankt!
    Vriendelijke groeten,
    Dany

  2. #2
    Fornicatorus Formicidae VideoRipper's Avatar
    Join Date
    Mar 2005
    Location
    Vicus Saltus Orientalem
    Posts
    5,708
    Dan heeft die gebruiker blijkbaar een andere karakterset ingesteld dan de standaard.
    TMemoryLeak.Create(Nil);

  3. #3
    Stijn Sanders develyoy's Avatar
    Join Date
    Jun 2008
    Location
    GentBrugge, Belgi?½
    Posts
    1,046
    Zou het helpen in dit geval om de applicatie's code page naar 65001 te schakelen?

  4. #4
    Hoi, allebei bedankt voor de reactie. Ik zal overschakelen naar code page 65001 eens proberen.
    In tussentijd weet ik ook dat mijn e-mail, waarin het € teken staat, bij die gebruiker wél goed getoond wordt.
    Vriendelijke groeten,
    Dany

  5. #5

    € teken in Deplhi10/Indy10 applicatie getoond als ?

    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;
    Vriendelijke groeten,
    Dany

  6. #6
    Quote Originally Posted by Dany View Post
    - in vervang in de mail body de (unicode) tekens '€' door het ansi code teken € (chr(128)):
    Wel gevaarlijk want chr(128) hoeft in plain/text niet altijd het euro-teken te zijn.

    Het kan bijvoorbeeld ook Ç zijn (wat het sinds het DOS tijdperk in Extended Ascii altijd is geweest voor Code page 437).

    Je moet dus zeker weten dat die plain/text ook met een code page weergegeven wordt die op chr(128) het euro-teken heeft staan.

    Als je direct verzend (en niet via Outlook of Thunderbird de mail opent) kun je misschien die Subject beter coderen met UTF-8.
    =?charset?encoding?encoded-text?=

    Dus bijvoorbeeld dit:
    =?utf-8?Q?hello?=
    Last edited by rvk; 08-Oct-18 at 12:59.

  7. #7
    John Kuiper
    Join Date
    Apr 2007
    Location
    Almere
    Posts
    8,747
    Volgens mij is indy 9 ook niet compatible met unicode. Vandaar dat dat goed ging.
    Delphi is great. Lazarus is more powerfull

  8. #8
    Hoi allen,

    Ik heb de oplossing gevonden op https://forums.embarcadero.com/messa...ssageID=895838 (oplossing van Rémi Lebeau).
    Er zijn ook geen problemen meer als het 'Subject' het € teken bevat.

    Bedankt Allemaal


    De code is dus geworden (de toevoegingen zijn aangeduid met '<----------', de vertaling van € naar chr(128) is weggelaten):
    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;
    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
              Body.Text := Body_.Text;
              ContentType := 'text/plain';
              CharSet:='UTF-16';  // <------
              ContentTransfer := 'base64'; // <------------
            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
              Body.Text := Body_.Text;
              ContentType := 'text/plain';
              CharSet:='UTF-16';  // <------
              ContentTransfer := 'base64'; // <------------
              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;
    Vriendelijke groeten,
    Dany

  9. #9
    Toch nog een wijziging moeten aanbrengen. Bepaalde mail servers (o.a. smtp-relay.sendinblue.com) hebben problemen met UTF-16: De tekst wordt weergegeven met tussen de tekens een extra spatie (vb "L o t t o T e s t M a i l 0 4 / 1 1 / 2 0 1 8 1 6 : 0 3 : 0 9" in plaats van "Lotto Test Mail 04/11/2018 16:03:09").

    Dus het is nu geworden:
    Code:
    CharSet:='UTF-8';
    in plaats van
    Code:
    CharSet:='UTF-16';
    (2x)
    Vriendelijke groeten,
    Dany

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •