E-Mail UTF8 problem?

E-Mail UTF8 problem?

Postby dutch » Tue Jul 06, 2021 3: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.
Image

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: Select all  Expand view
    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 19.01 / 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)
User avatar
dutch
 
Posts: 1540
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: E-Mail UTF8 problem?

Postby cnavarro » 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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: E-Mail UTF8 problem?

Postby dutch » Tue Jul 06, 2021 2:31 pm

Dear cnavaroo,

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

Code: Select all  Expand view
: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 19.01 / 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)
User avatar
dutch
 
Posts: 1540
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: E-Mail UTF8 problem?

Postby richard-service » Tue Jul 06, 2021 3: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 (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 803
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: E-Mail UTF8 problem?

Postby dutch » Wed Jul 07, 2021 2: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 19.01 / 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)
User avatar
dutch
 
Posts: 1540
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: E-Mail UTF8 problem?

Postby dutch » Sat Jul 10, 2021 3:17 am

I try as found in Internet as ;
Code: Select all  Expand view
            :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 19.01 / 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)
User avatar
dutch
 
Posts: 1540
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: E-Mail UTF8 problem?

Postby dutch » Sun Jul 18, 2021 9:45 am

up.
Regards,
Dutch

FWH 19.01 / 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)
User avatar
dutch
 
Posts: 1540
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: E-Mail UTF8 problem?

Postby cnavarro » 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: Select all  Expand view

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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: E-Mail UTF8 problem?

Postby dutch » Sun Jul 18, 2021 4: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: Select all  Expand view

cHtml+='<META content="text/html;" http-equiv="Content-Type>"'+CRLF
 

Thanks for your suggestion.
Regards,
Dutch

FWH 19.01 / 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)
User avatar
dutch
 
Posts: 1540
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: E-Mail UTF8 problem?

Postby cnavarro » Sun Jul 18, 2021 6:37 pm

Ok, look, this work ok

Image

and received

Image

Code: Select all  Expand view

   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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: E-Mail UTF8 problem?

Postby dutch » Mon Jul 19, 2021 3: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?

Image

Code: Select all  Expand view
#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

Image

and received

Image

Code: Select all  Expand view

   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 19.01 / 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)
User avatar
dutch
 
Posts: 1540
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: E-Mail UTF8 problem?

Postby cnavarro » 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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: E-Mail UTF8 problem?

Postby dutch » Mon Jul 19, 2021 1: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 19.01 / 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)
User avatar
dutch
 
Posts: 1540
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: E-Mail UTF8 problem?

Postby cnavarro » Mon Jul 19, 2021 1: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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: E-Mail UTF8 problem?

Postby dutch » Wed Jul 21, 2021 5: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 19.01 / 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)
User avatar
dutch
 
Posts: 1540
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 51 guests