FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour E-Mail UTF8 problem?
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
E-Mail UTF8 problem?
Posted: Tue Jul 06, 2021 03:18 AM
Dear All,

I've sent mail via "CDO.Message" without any problem. Now I try to use with UTF8 (FW_Unicode(.T.)), it got the problem. Thai Language is unreadable in Email program such as Outlook or Gmail on browser as picture.


This is my code. The sending method is no problem but It look like Outlook or Gmail do not support Unicode. I do not understand.
Code (fw): Select all Collapse
    cHtml:='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'+CRLF
    cHtml+='<HTML><HEAD>'+CRLF
    cHtml+='<META content="text/html; charset=utf-8" http-equiv=Content-Type>'+CRLF
    cHtml+='<META name=GENERATOR content="MSHTML 8.00.6001.18783">'+CRLF
    cHtml+='<STYLE></STYLE>'+CRLF
    cHtml+='</HEAD>'+CRLF
    cHtml+='<BODY bgColor=#ffffff>'
    cHtml+='<DIV>'
     
    cHtml += cMsg+'<br>'
    
    cHtml += '</DIV></BODY></HTML>'    
    
    ?cHtml
    
    TRY
      oEmailCfg := CREATEOBJECT( "CDO.Configuration" )
      WITH OBJECT oEmailCfg:Fields
         :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value                 := cSmtp // "smtp.gmail.com"
         :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value         := iif(lSSL,465,25)  // 465 SSL
         :Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value              := 2   // Remote SMTP = 2, local = 1
         :Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value       := iif(lAuthen,.T.,.F.) // .T.
         :Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value                 := lSSL // .T.
         :Item( "http://schemas.microsoft.com/cdo/configuration/savesentitems" ):Value          := lSave
         :Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value           := cSender  //  "hotel@gmail.com"
         :Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value           := cPass // Password
         :Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 30
         :Update()
      END WITH
    
    CATCH oError
    
        if lMsgInfo
            MsgAlert("Could not setting message" +CRLF+  ;
                "Error : " + TRANSFORM(oError:GenCode, NIL) +CRLF+  ;
                "SubCode : " + TRANSFORM(oError:SubCode, NIL) +CRLF+  ;
                    "OSCode : " + TRANSFORM(oError:OsCode, NIL) +CRLF+  ;
                    "SubSystem : " + TRANSFORM(oError:SubSystem, NIL) +CRLF+  ;
                    "Message : " + oError:Description )
        else
        nSuccess := 0
        end
        
        cErrorDesc := if(IsInternet(),rtrim(oError:Description),'Internet Connection Fail')
        
    END
    oError:=NIL
    
    TRY
        oEmailMsg := CREATEOBJECT ( "CDO.Message" )
        WITH OBJECT oEmailMsg
            :Configuration  := oEmailCfg
            :From               := chr(34)+cDisplay+" "+chr(34)+ "<"+cReply+">" // cSender  // This will be displayed in the From (The email id does not appear)
            if !empty(cTo)  // check no receiver for Mail advertising, it will send to BCC instead
                  :To           := cTo   // <-----   Place your email address
            end
            if !empty(cBCC) // check no receiver for Mail advertising, it will send to BCC instead
                  :Bcc          := cBCC
            end
            :Subject            := rtrim(cSubject)  //   "Email Test Message from GMail"
            :ReplyTo            := cReply
            :MDNRequested   := .F.  // .F. anyone use without warning
            if !empty(cAttach)
                  :AddAttachment(cAttach)
            end
            :BodyPart:Charset := "utf-8" 
            :HTMLBody := cHtml
        END WITH
        oEmailMsg:Send()

    CATCH oError
        nSuccess := 0

        if lMsgInfo
           MsgAlert("Could not send message" + CRLF+ ;
                 "Error : " + TRANSFORM(oError:GenCode, NIL) + CRLF+;
                  "SubCode : "  + TRANSFORM(oError:SubCode, NIL) + CRLF+ ;
                   "OSCode : "+ TRANSFORM(oError:OsCode, NIL) + CRLF +;
                    "SubSystem : " + TRANSFORM(oError:SubSystem, NIL) + CRLF+ ;
                    "Message : " + oError:Description )
        end

        cErrorDesc := if(IsInternet(),rtrim(oError:Description),'Internet Connection Fail')
    
    END

Thank you in advance for any help or suggestion.
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: E-Mail UTF8 problem?
Posted: Tue Jul 06, 2021 11:04 AM

Try not including the utf-8 charset in as html encoding and tell me what you get

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: E-Mail UTF8 problem?
Posted: Tue Jul 06, 2021 02:31 PM
Dear cnavaroo,

I've include in header and body already but not successful.
Code (fw): Select all Collapse
cHtml+='<META content="text/html; charset=utf-8" http-equiv=Content-Type>'+CRLF

Code (fw): Select all Collapse
 :BodyPart:Charset := "utf-8"

cnavarro wrote:Try not including the utf-8 charset in as html encoding and tell me what you get


Thank you for your reply.
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 866
Joined: Tue Oct 16, 2007 08:57 AM
Re: E-Mail UTF8 problem?
Posted: Tue Jul 06, 2021 03:35 PM

Hi, Dutch

I have not try your code. How about PRG save as to Utf8 (Utf8 include BOM )

Best Regards,



Richard



Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 32bit

MySQL v8.0

Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 64bit
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: E-Mail UTF8 problem?
Posted: Wed Jul 07, 2021 02:01 AM
Dear Richard,

Yes, I've saved UTF8. I used UTF8 for support multi-language. I show on dialog and program correctly but it shows incorrectly in email program such as Outlook and Gmail as 3 bytes character. I think the program send UTF8 but email program got different that while it show unreadable with 3 times character.
Example
Thai
prgram = 'ทดสอบ' // Test (English)
email = 'เธ—เธ”เธชเธญเธš' [ 5x3 = 15 characters ]
richard-service wrote:Hi, Dutch

I have not try your code. How about PRG save as to Utf8 (Utf8 include BOM )


Thank you Richard for suggestion.
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: E-Mail UTF8 problem?
Posted: Sat Jul 10, 2021 03:17 AM
I try as found in Internet as ;
Code (fw): Select all Collapse
            :HTMLBody               := cHtml
            :BodyPart:Charset       := "utf-8" 
            :TextBodyPart:Charset := "utf-8" 
            :HTMLBodyPart:Charset := "utf-8"

Still doesn't work.
Any idea most pleasure.
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: E-Mail UTF8 problem?
Posted: Sun Jul 18, 2021 09:45 AM

up.

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: E-Mail UTF8 problem?
Posted: Sun Jul 18, 2021 10:33 AM
Dear Dutch,
Please try without including utf-8 in any element and tell me what you get ( not utf8 in body, not utf8 in any item )

Code (fw): Select all Collapse
cHtml+='<META content="text/html;" http-equiv="Content-Type>"'+CRLF
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: E-Mail UTF8 problem?
Posted: Sun Jul 18, 2021 04:26 PM
Dear Navarro,

It is still unreadable and show as below
??-??"????????šTest

cnavarro wrote:Dear Dutch,
Please try without including utf-8 in any element and tell me what you get ( not utf8 in body, not utf8 in any item )

Code (fw): Select all Collapse
cHtml+='<META content="text/html;" http-equiv="Content-Type>"'+CRLF

Thanks for your suggestion.
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: E-Mail UTF8 problem?
Posted: Sun Jul 18, 2021 06:37 PM
Ok, look, this work ok



and received



Code (fw): Select all Collapse
   cHtml  += '<META content="text/html; charset=utf-8" http-equiv=Content-Type>'

// and

      oMsg = CreateObject( "CDO.Message" )
.../...
    oMsg:BodyPart:Charset := "utf-8"
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: E-Mail UTF8 problem?
Posted: Mon Jul 19, 2021 03:09 AM
Dear cnavarro,

I try as your suggestion but it doesn't work. I saved this file as UTF8-No Bom already. It shows in my Outlook as picture.
Cloud you review this below code that I try as your suggestion please?



Code (fw): Select all Collapse
#Include "FiveWin.Ch"
*-------------------------------------------------*
Function Main()
*-------------------------------------------------*
Local oEmailCfg,oEmailMsg,oError,cHtml

local cMsg 

cMsg := ''
cMsg+= 'Good Morning'+CRLF
cMsg+= 'สวัสดีตอนเช้า'+CRLF
cMsg+= 'おはようございます'+CRLF
cMsg+= '早上好'


cHtml:='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'
cHtml+='<HTML><HEAD>'
cHtml+='<META content="text/html; charset=utf-8" http-equiv=Content-Type>'
cHtml+='<META name=GENERATOR content="MSHTML 8.00.6001.18783">'
cHtml+='<STYLE></STYLE>'
cHtml+='</HEAD>'
cHtml+='<BODY bgColor=#ffffff>'
cHtml+='<DIV>' // <FONT size=2 color=blue face=CordiaUPC>'

cHtml+= cMsg 

//cHtml+='</FONT></DIV></BODY></HTML>'
cHtml+='</DIV></BODY></HTML>'

MsgInfo(cMsg)

TRY
  oEmailCfg := CREATEOBJECT( "CDO.Configuration" )
  WITH OBJECT oEmailCfg:Fields
     :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := "smtp.gmail.com"
     :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := 465
     :Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value := 2   // Remote SMTP = 2, local = 1
     :Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := .T.
     :Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value := .T.
     :Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value := "XXXXXXXXX@gmail.com"
     :Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := "XXXXXXXXX" // Password
     :Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 30
     :Update()
  END WITH
CATCH oError
  MsgInfo( "Could not send message" + ";"  + ;
         "Error: " + TRANSFORM(oError:GenCode, NIL) + ";" + ;
         "SubC: " + TRANSFORM(oError:SubCode, NIL) + ";" + ;
         "OSCode: " + TRANSFORM(oError:OsCode, NIL) + ";" + ;
         "SubSystem: " + TRANSFORM(oError:SubSystem, NIL) + ";" + ;
         "Message: " + oError:Description )
END
oError:=NIL

TRY
    oEmailMsg := CREATEOBJECT ( "CDO.Message" )
    WITH OBJECT oEmailMsg
        :Configuration = oEmailCfg
        :From = chr(34)+"Dutch "+chr(34)+ "<dutchez4@gmail.com>" // This will be displayed in the From (The email id does not appear)
        :To = "pairat@easyfo.com"    // <-----   Place your email address
        :Subject = "Email Test Message from GMail"
        :MDNRequested = .T.
        :BodyPart:Charset := 'utf-8'
        :HTMLBody = cHtml
//        :AddAttachment(curdrive()+':\'+curdir()+'\sendmail.prg')
    END WITH
    oEmailMsg:Send()
CATCH oError
    MsgInfo("Could not send message" + ";"  + CRLF+ ;
            "Error: " + TRANSFORM(oError:GenCode, NIL) + ";" + CRLF+;
            "SubC: "  + TRANSFORM(oError:SubCode, NIL) + ";" + CRLF+ ;
            "OSCode: "+ TRANSFORM(oError:OsCode, NIL) + ";" + CRLF +;
            "SubSystem: " + TRANSFORM(oError:SubSystem, NIL) + ";" +CRLF+ ;
            "Message: " + oError:Description )
END
// MsgInfo("Reached the end of the code")
Return .T.


cnavarro wrote:Ok, look, this work ok



and received



Code (fw): Select all Collapse
   cHtml  += '<META content="text/html; charset=utf-8" http-equiv=Content-Type>'

// and

      oMsg = CreateObject( "CDO.Message" )
.../...
    oMsg:BodyPart:Charset := "utf-8"
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: E-Mail UTF8 problem?
Posted: Mon Jul 19, 2021 10:55 AM
dutch wrote:Dear cnavarro,

I try as your suggestion but it doesn't work. I saved this file as UTF8-No Bom already. It shows in my Outlook as picture.
Cloud you review this below code that I try as your suggestion please?



Dear Dutch
What file are you referring to?
I have not had to do anything
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: E-Mail UTF8 problem?
Posted: Mon Jul 19, 2021 01:15 PM
Dear cnavarro,

The source code file has saved for supporting utf8.
cnavarro wrote:
dutch wrote:Dear cnavarro,

I try as your suggestion but it doesn't work. I saved this file as UTF8-No Bom already. It shows in my Outlook as picture.
Cloud you review this below code that I try as your suggestion please?



Dear Dutch
What file are you referring to?
I have not had to do anything
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: E-Mail UTF8 problem?
Posted: Mon Jul 19, 2021 01:25 PM

Dear Dutch
Fivedit allows saving the file in UTF8 (also not BOM), and BIG ENDIAN, but I didn't have to do that either for it to work correctly.
I have looked at your code and I do not see anything that prevents it from working properly.
Do you have a language selection or code page in your application?
But, I use FW_SetUnicode( .T. ) in my application

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: E-Mail UTF8 problem?
Posted: Wed Jul 21, 2021 05:39 AM
Dear cnavarro,

I added FW_SetUnicode( .T. ) at the top of the program but no luck. It still doesn't work. Cloud you please test my code and if it success, please send me back that file (if do not disturb you)?
cnavarro wrote:Dear Dutch
Fivedit allows saving the file in UTF8 (also not BOM), and BIG ENDIAN, but I didn't have to do that either for it to work correctly.
I have looked at your code and I do not see anything that prevents it from working properly.
Do you have a language selection or code page in your application?
But, I use FW_SetUnicode( .T. ) in my application


Thank you so much for kind help.
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)