Send Emails from Fivewin application

Send Emails from Fivewin application

Postby anserkk » Thu Oct 19, 2023 9:47 am

Hi,

Can anyone recommend a reliable solution to send Emails from the Fivewin application?

Regards

Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Send Emails from Fivewin application

Postby Antonio Linares » Thu Oct 19, 2023 10:31 am

Dear Anser,

Harbour provides a hb_SendMail() function

Could hb_SendMail() users provide feeback if it is working fine for them ?

many thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Send Emails from Fivewin application

Postby Ruth » Wed May 08, 2024 10:17 am

Dear friends,

we are trying to send mails directly from the program.
I found this post about hb_SendMail() ... would this function work in mod_harbour as well and would anyone be so kind as to help me out with your knowledge please...

I have office365 and it provided me with client_id, tenant_id, etc which I stored in environment variables. I suppose this should be parameters of the hb_sendMail() function then... :?:


Any hints and help would be so greatly appreciated. thanks in advance and kind regards
Ruth
User avatar
Ruth
 
Posts: 169
Joined: Fri Dec 07, 2007 1:26 pm

Re: Send Emails from Fivewin application

Postby karinha » Wed May 08, 2024 10:40 am

Good morning Ruth, do you only use an example in MOD_HARBOUR?

Buenos días Ruth, ¿puede ser solo un ejemplo en MOD_HARBOUR?

I have it, but it's for desktop.

Lo tengo pero es para desktop.

Tks, gracias.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7808
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Send Emails from Fivewin application

Postby paquitohm » Wed May 08, 2024 10:49 am

Hi,

Try with powershell !

Regards
paquitohm
 
Posts: 262
Joined: Fri Jan 14, 2022 8:37 am

Re: Send Emails from Fivewin application

Postby Ruth » Wed May 08, 2024 10:52 am

Dear Mr. Santos, I would greatly appreciate your example. May I kindly ask for it...
I use (am learning) MOD_HARBOUR and desktop :-)
Kind regards Ruth
User avatar
Ruth
 
Posts: 169
Joined: Fri Dec 07, 2007 1:26 pm

Re: Send Emails from Fivewin application

Postby karinha » Wed May 08, 2024 10:59 am

Ruth wrote:Dear Mr. Santos, I would greatly appreciate your example. May I kindly ask for it...
I use (am learning) MOD_HARBOUR and desktop :-)
Kind regards Ruth


Download complete:

https://mega.nz/file/FQFWgIDT#kvRtIHIesRpTw9I8CxJenTRikG4VXM0t_7J8qVQsOX8

https://mega.nz/file/UR9AiKQR#loYk6r3qRMkBNcN5vxErGsNFkUWOungL4q43QyYDL0Y

https://mega.nz/file/ZY0lCC4b#J087eB2aPhfZiNynwgaEnkwvrPF2P6y7Pifxl_41Qco

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7808
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Send Emails from Fivewin application

Postby karinha » Wed May 08, 2024 11:11 am

Ruth, use Google Traductor:

https://imgur.com/djicmRs

Image

Regards, saludos
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7808
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Send Emails from Fivewin application

Postby Silvio.Falconi » Wed May 08, 2024 11:48 am

anserkk wrote:Hi,

Can anyone recommend a reliable solution to send Emails from the Fivewin application?

Regards

Anser


Image


USe this
Code: Select all  Expand view
static Function EmailProva2(cNomeMittente,cMailMittente,cServerSmtp,nPorta,cNomeUtente,cPassword,lcopianascostaalmittente,cmail)
   Local  nBottom   := 33.2
   Local  nRight    :=  58
   Local  nWidth    :=  Max( nRight * DLG_CHARPIX_W, 180 )
   Local  nHeight   :=  nBottom * DLG_CHARPIX_H
   Local oDlgTest
   Local cDlgTitle  := "Invio Email di Prova"
   Local aGet[10]
   local oTitle1,oImagetitle
   local cImageTitle:= "Mail2.bmp"
   local oFont2,oFontBold2,oFontBold3
   local obtn2[3]
   local nItem := 0
   local x
   local lRet := .f.

  local cSubject:="Email di prova"
  local cMessage:="Questa è una e-mail di prova inviata da ..."
  local cCC:= space(60)
  local cCCn:= IIF( lcopianascostaalmittente,cMailMittente,space(60))


   local oMsg  := CreateObject( "CDO.Message" )
   local oConf := CreateObject( "CDO.Configuration" )
   local cSchema := "http://schemas.microsoft.com/cdo/configuration/"

   local oBtn1,oBtn3



   IF empty(cNomeMittente)
      msginfo("Inserire il nome utente")
      return nil
   Endif

    IF empty(cMailMittente)
      msginfo("Inserire la casella di posta")
      return nil
   Endif

    IF empty(cPassword)
      msginfo("Inserire la password")
      return nil
   Endif



   DEFINE FONT oFont2 NAME 'Tahoma' SIZE 0, -12
   DEFINE FONT oFontBold2 NAME 'Tahoma' SIZE 0, -18 BOLD
   DEFINE FONT oFontBold3 NAME 'Tahoma' SIZE 0, -12 BOLD




     DEFINE DIALOG oDlgTest          ;
         SIZE nWidth, nHeight   PIXEL  ;
         TITLE cDlgTitle

    oDlgTest:lHelpIcon := .F.
    oDlgTest:nStyle    := nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION,  4 )


      @ 0,0 TITLE  oTitle1 OF oDlgTest size 500, 40  SHADOW NOSHADOW   ;
                               GRADIENT { { 1,CLR_WHITE, LIGHTCYAN } }

        @ 10, 12 TITLETEXT OF oTitle1 TEXT "Invio e-mail" FONT oFontBold2 COLOR CLR_BLACK
        @ 38, 42 TITLETEXT OF oTitle1 TEXT "Inserisci destinatari e testo del messaggio" FONT oFont2 COLOR CLR_BLACK
        @ 10, oTitle1:nWidth-120 TITLEIMG  oImagetitle  OF oTitle1 BITMAP cImageTitle TRANSPARENT


        @ 50 , 10 SAY  "A:" of oDlgTest  size 80,10 PIXEL FONT oFontBold3  COLOR CLR_BLACK
        @ 50,50 GET aGet[1] VAR cMailMittente  size 170,10 PIXEL FONT oFont2  UPDATE

        @ 70 , 10 SAY  "Oggetto:" of oDlgTest  size 80,10 PIXEL FONT oFontBold3  COLOR CLR_BLACK
        @ 70,50 GET aGet[2] VAR cSubject  size 170,10 PIXEL FONT oFont2  UPDATE

        @ 90 , 10 SAY  "CC:" of oDlgTest  size 80,10 PIXEL FONT oFontBold3  COLOR CLR_BLACK
        @ 90,50 GET aGet[3] VAR cCC  size 170,10 PIXEL FONT oFont2  UPDATE

        @ 110 , 10 SAY  "CCn:" of oDlgTest  size 80,10 PIXEL FONT oFontBold3  COLOR CLR_BLACK
        @ 110,50 GET aGet[4] VAR cCCn  size 170,10 PIXEL FONT oFont2  UPDATE

        @ 130,50 GET aGet[5] VAR cMessage  size 170,45 PIXEL FONT oFont2  UPDATE MEMO


         @ 185,50 ListBox oList Var nItem ITEMS aAttach Size 170,50 Pixel

          * @ 190, 25 Button "Agg" Size 20,08 Pixel Action ADDItem()
         *  @ 205, 25 Button "Can" Size 20,08 Pixel Action DELItem()

         oBtn1:= TUrlLink():New( 190, 2, oDlgTest, .T., .F., oFont2, "Aggiungi", "Aggiungi allegato" )
         oBtn1:bAction := { |nRow, nCol| ADDItem()  }
         oBtn3:= TUrlLink():New( 205, 2, oDlgTest, .T., .F., oFont2, "Cancella", "Cancella allegato" )
         oBtn3:bAction := { |nRow, nCol| DELItem()  }




         @ 236, 120 Button obtn2[2] Prompt "&Conferma"  of oDlgTest  size 50,12 PIXEL FONT oFont2 DEFAULT ACTION  ( oDlgTest:end( IDOK )  )
         @ 236, 175 Button obtn2[3] Prompt "&Annulla"   of oDlgTest  size 50,12 PIXEL FONT oFont2 CANCEL  ACTION  ( oDlgTest:end( IDCANCEL ) )
         ACTIVATE DIALOG oDlgTest  centered





  if oDlgTest:nresult == IDOK
        //============================================================================================//
        TRY
           oCfg := CREATEOBJECT( "CDO.Configuration" )
             WITH OBJECT oCfg:Fields
                  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver"       ):Value := alltrim(cServerSmtp)
                  :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport"   ):Value := val(alltrim(nPorta))
                  :Item( "http://schemas.microsoft.com/cdo/configuration/sendusing"        ):Value := 2
                  :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 := alltrim(cNomeUtente)
                  :Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword"     ):Value := alltrim(cPassword)
                  :Update()
             END WITH


             lRet := .t.

         CATCH oError
           MsgInfo( "Non è possibile inviare l'email!!!"  +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+ ;
                    "Messaggio: "   + oError:Description, "Attenzione" )

         END


         if lRet
                TRY
                 oMsg:To = alltrim(cmail)
                 oMsg:From =chr(34)+alltrim(cNomeMittente)+" "+chr(34)+ "<"+alltrim(cMailMittente)+">"
                 oMsg:Subject = alltrim(cSubject)
                 oMsg:HTMLBody = alltrim(cMessage)
                 oMsg:Sender = alltrim(cNomeMittente)
                 oMsg:Organization = "Family"

                IF lcopianascostaalmittente
                       oMsg:ReplyTo = alltrim(cMailMittente)
                 endif


                       For x := 1 To Len( aAttach )
                           if aAttach[x] <> NIL
                              oMsg:AddAttachment(AllTrim(aAttach[x]))
                           endif
                       Next


                 oMsg:Configuration = oCfg
                 oMsg:Send()

                  CATCH
                  MsgInfo("Non è possibile inviare il messaggio di posta")
                  lRet := .f.
                END

      endif



          Endif

        //============================================================================================//

    return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: Send Emails from Fivewin application

Postby Ruth » Wed May 08, 2024 6:08 pm

...thank you very much for the wonderful examples and your friendly help. Kind regards Ruth
User avatar
Ruth
 
Posts: 169
Joined: Fri Dec 07, 2007 1:26 pm

Re: Send Emails from Fivewin application

Postby karinha » Wed May 08, 2024 6:55 pm

Ruth, a simple example for you to understand better.

Ruth, un ejemplo sencillo para que lo entiendas mejor.

Code: Select all  Expand view

// C:\FWH\SAMPLES\RUTHMAIL.PRG

#include "FiveWin.ch"

MEMVAR smtpserver, serverport, sendusing, authenticate, usessl, username, ;
       password, timeout

MEMVAR cFrom, cTo, cSubject, cTextBody

FUNCTION Main()

   PRIV smtpserver, serverport, sendusing, authenticate, usessl, username, ;
        password, timeout

   PRIV cFrom, cTo, cSubject, cTextBody

   smtpserver   := "smtp.pleno.com.br"
   serverport   := 587
   sendusing    :=   2
   authenticate := .T.
   usessl       := .F. // .T. or .F.
   username     := "joao@pleno.com.br" //<your_email>
   password     := "XXXXXXX"           // <sua_senha>
   timeout      := 60

   cFrom        := "joao@pleno.com.br"
   cTo          := "kapiabafwh@gmail.com"
   cSubject     := "RUTH send with Gmail account RUTH"
   cTextBody    := "RUTH: Teste de Email-Only TEST"

   SendMailCDO()

RETURN NIL

FUNCTION SendMailCDO()
 
   LOCAL objMsg, cHtml, oError
   LOCAL msgConf, lRet := .F.
 
   /*
   ? smtpserver, serverport, sendusing, authenticate, usessl, username, ;
     password, timeout
   */


   //' Server Configuration
   TRY

      msgConf := CreateObject("CDO.Configuration")

      WITH OBJECT msgConf:Fields

      :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver"       ):Value := smtpserver
      :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport"   ):Value := serverport
      :Item( "http://schemas.microsoft.com/cdo/configuration/sendusing"        ):Value := sendusing
      :Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := authenticate
      :Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl"       ):Value := usessl
      :Item( "http://schemas.microsoft.com/cdo/configuration/sendusername"     ):Value := username
      :Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword"     ):Value := password
      :Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := timeout
 
      :Update()
 
      END WITH

 
   CATCH oError

      MsgInfo("Configuration instance object error " + ";"  + 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
 
   //' Email
 
   TRY

      objMsg  := CreateObject("CDO.Message")

      WITH OBJECT objMsg

      :Configuration := msgConf
      :From          := cFrom
      :To            := cTo
      :Subject       := cSubject
      :TextBody      := cTextBody
      :MDNRequested  := .F. // Indicates whether a Message Disposition Notification is requested on a message.
      :Send()

      END WITH
 
      // objMsg:Send()
      lRet := .T.

   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 )

      RETURN NIL

   END

   IF lRet // := .T.

      ? "PERFECT RUTH"

   ENDIF
 
RETURN NIL

// FIN / END - kapiabafwh@gmail.com
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7808
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Send Emails from Fivewin application

Postby Ruth » Wed May 08, 2024 9:11 pm

Dear Mr. Santos,

Thank you very, very much.
I got this...
Image
which made me very happy :)

Thank you again and kind regards
Ruth
User avatar
Ruth
 
Posts: 169
Joined: Fri Dec 07, 2007 1:26 pm

Re: Send Emails from Fivewin application

Postby karinha » Thu May 09, 2024 11:26 am

Great!

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7808
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Send Emails from Fivewin application

Postby Ruth » Tue May 14, 2024 1:56 pm

Dear Mr. Santos, dear all fivewinners,

please can I ask for your experience and help one more time.

I am able to send also an image with the code you kindly gave to me by switching from
:TextBody to :HTMLBody.

Everything works fine as long as the image is somewhere located on a server ...

I post the code here:
Code: Select all  Expand view

// C:\FWH\SAMPLES\RUTHMAIL.PRG

#include "FiveWin.ch"
#Include "Outlook.ch"
#Include "Mail.ch"


MEMVAR smtpserver, serverport, sendusing, authenticate, usessl, username, ;
       password, timeout

MEMVAR cFrom, cTo, cSubject, cTextBody, cImgBase64, cImg, cBase64

FUNCTION Main()

   PRIV smtpserver, serverport, sendusing, authenticate, usessl, username, ;
        password, timeout

   PRIV cFrom, cTo, cSubject, cTextBody, cImgBase64

   smtpserver   := "smtp.iomartmail.com"
   serverport   := 587
   sendusing    :=   2
   authenticate := .T.
   usessl       := .F. // .T. or .F.
   username     := "" //<your_email>
   password     := ""           // <sua_senha>
   timeout      := 60

   cFrom        := "info@winhotel.at"
   cTo          := "hotel@bergland.info"
   cSubject     := "RUTH an RUTH"
  // cTextBody    := "RUTH: Teste de Email-Only TEST"
 
 

  cImgBase64   := hb_base64encode(MEMOREAD("c:\fwh\samples\img\start_slide1.jpg"))
 


   SendMailCDO()

RETURN NIL

FUNCTION SendMailCDO()
 
   LOCAL objMsg, cHtml, oError
   LOCAL msgConf, lRet := .F.
 
   /*
   ? smtpserver, serverport, sendusing, authenticate, usessl, username, ;
     password, timeout
   */


   //' Server Configuration
   TRY

      msgConf := CreateObject("CDO.Configuration")

      WITH OBJECT msgConf:Fields

      :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver"       ):Value := smtpserver
      :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport"   ):Value := serverport
      :Item( "http://schemas.microsoft.com/cdo/configuration/sendusing"        ):Value := sendusing
      :Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := authenticate
      :Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl"       ):Value := usessl
      :Item( "http://schemas.microsoft.com/cdo/configuration/sendusername"     ):Value := username
      :Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword"     ):Value := password
      :Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := timeout
 
      :Update()
 
      END WITH

 
   CATCH oError

      MsgInfo("Configuration instance object error " + ";"  + 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
 
   //' Email
 
   TRY

      objMsg  := CreateObject("CDO.Message")

      WITH OBJECT objMsg

      :Configuration := msgConf
      :From          := cFrom
      :To            := cTo
      :Subject       := cSubject
     // :TextBody      := cTextBody
      :HTMLBody      := '<h1>HTML Content Here</h1><p>This is a TEST MAIL sent from FiveWin using CDO.</p>';
                     +  '<img src="https://bergland.info/img/start_slide1.jpg" >';
                    // +  '<img src="data:image/jpeg;base64,' + cImgBase64 + '" > ';
                     + '<p><b>Test Ende</b></p>' // HTML formatted content
      :MDNRequested  := .F. // Indicates whether a Message Disposition Notification is requested on a message.
      :Send()

      END WITH
 
      // objMsg:Send()
      lRet := .T.

   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 )

      RETURN NIL

   END

   IF lRet // := .T.

      ? "PERFECT RUTH"
     

   ENDIF
 
RETURN NIL

// FIN / END - kapiabafwh@gmail.com
 


And also the screenshot of the email I am able to receive:
Image
But I can´t get
Code: Select all  Expand view
hb_base64encode(MEMOREAD("c:\fwh\samples\img\start_slide1.jpg"))


and then
Code: Select all  Expand view
<img src="data:image/jpeg;base64,' + cImgBase64 + '" >


running. Maybe you have a hint for me? I would really appreciate it very much.

In the meantime kind regards to all of you and thank you
Ruth
User avatar
Ruth
 
Posts: 169
Joined: Fri Dec 07, 2007 1:26 pm

Re: Send Emails from Fivewin application

Postby paquitohm » Tue May 14, 2024 2:32 pm

Hello,

I already recommended powershell to you before. Today we will focus on it. CDO does not allow sending from accounts with the SSL protocol, that is, all those that are Outlook.
In my case I maintain CDO but I have the new one with powershell, that is, a .ps1 file that is called from harbour. It doesn't matter if it is powershell or php, the question is to use something external that is compatible with current standards and is prepared for the new revisions that will arrive, which eliminates CDO because it is a system that is no longer updated

Regards
paquitohm
 
Posts: 262
Joined: Fri Jan 14, 2022 8:37 am

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 33 guests