Email with SSL / TLS using FiveWin

Email with SSL / TLS using FiveWin

Postby Jimmy » Wed Jun 29, 2022 2:24 pm

hi,

i found CLASS TSmtp and CLASS TPop3.

Question : can they use SSL / TLS :?:
if yes, how :idea:

what else can i use under FiveWin :idea:

---

i also use CDO but it also fail with TLS > 1.1
under HMG i use hbTIP but i was told to use hbCURL and OpenSSL instead.
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Email with SSL / TLS using FiveWin

Postby Antonio Linares » Thu Jun 30, 2022 3:15 pm

Dear Jimmy,

> i found CLASS TSmtp and CLASS TPop3

Those classes don't support SSL / TLS

Please search for SSL in these forums
regards, saludos

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

Re: Email with SSL / TLS using FiveWin

Postby Antonio Linares » Thu Jun 30, 2022 3:20 pm

regards, saludos

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

Re: Email with SSL / TLS using FiveWin

Postby Jimmy » Thu Jun 30, 2022 11:10 pm

hi Antonio,

thx for Answer.

as i know Collaboration Data Objects (CDO) is not support any more since Server 2016
Server 2016 use Exchange Web Services (EWS) but it have no COM Interface.
not sure if CDO will work in Future

---

i do use hbTIP with SSL / TLS but i was told to change it
i need SSL / TLS > 1.1

so a can not use CLASS TSmtp and CLASS TPop3

i was told to use hbCURL but found no Sample for Email

---

under Windows 10/11 we have CURL.EXE

i have found Sample using Parameter to send Email using CURL.EXE

Question : is hbCURL and CURL.EXE "same" :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Email with SSL / TLS using FiveWin

Postby Antonio Linares » Fri Jul 01, 2022 5:34 am

Dear Jimmy,

> Question : is hbCURL and CURL.EXE "same" :?:

Yes, they should offer the same functionality

> i have found Sample using Parameter to send Email using CURL.EXE

Please let us know it so we can find a way to use it with hbcurl, many thanks
regards, saludos

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


Re: Email with SSL / TLS using FiveWin

Postby Jimmy » Fri Jul 01, 2022 3:49 pm

hi Antonio,

Antonio Linares wrote:> i have found Sample using Parameter to send Email using CURL.EXE
Please let us know it so we can find a way to use it with hbcurl, many thanks

have not test it yet
Code: Select all  Expand view  RUN
              aadd(acCmd, " -# --insecure  ")

              IF adata [2][6] // use ssl
                 aadd(acCmd, "--ssl-reqd --url smtps://")
              Else
                 aadd(acCmd, "--url smtp://")
              EndIF

              // add smtp
              aadd(acCmd, cSmtp+":"+aData[1][2])
              aadd(acCmd," --user "+cFrom+":"+cPassword)
              aadd(acCmd," --mail-from "+cFrom+"|"+cUser )
              aadd(acCmd," --mail-rcpt "+cTo )

              Waitwindow("mail body creation",.T.)
              MailEncode(lmsg,,aCCmd,cSubject,aBody)
              Waitwindow()
 
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Email with SSL / TLS using FiveWin

Postby Jimmy » Fri Jul 01, 2022 3:50 pm

hi,
hmpaquito wrote:hbCURL use in Harbour:

thx for help.

your link show Sample using CURL and sFTP but i want to use it for Email
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Email with SSL / TLS using FiveWin

Postby toninhofwi » Tue Aug 09, 2022 3:31 pm

Hi, try use chilkat activex dll, there are a lot of foxPro samples that can be used with harbour

https://www.example-code.com/foxpro/smtp.asp

regards
toninhofwi
 
Posts: 172
Joined: Tue Oct 18, 2005 10:01 am

Re: Email with SSL / TLS using FiveWin

Postby Jimmy » Tue Aug 09, 2022 6:59 pm

hi

thx for Answer.

i do not like to use "external" 3-PP Tool
i want to "learn" how it work while all is Windows API

---

have read in German Xbase++ Forum

Header-Eintrag "Message-ID:".
Den setzen wir auf eine UID mit angehängtem Domain-Namen, also so:

Message-ID: <821f7e56-8871-4657-ac3b-1504fbbd0456@mmorthosoft.de>

but i don´t know "where" to Set Message-ID
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Email with SSL / TLS using FiveWin

Postby elvira » Tue Aug 09, 2022 7:52 pm

Antonio,

Could you please provide a smtp class that works with Gmail and ssl?

Thank you in advance!
elvira
 
Posts: 516
Joined: Fri Jun 29, 2012 12:49 pm

Re: Email with SSL / TLS using FiveWin

Postby Jimmy » Tue Aug 09, 2022 10:18 pm

hi,
elvira wrote:Could you please provide a smtp class that works with Gmail and ssl?

as i know FiveWin CLASS TSmtp and CLASS TPop3 do not use SSL.

under HMG i use harbour hbTIP which work
... but i was told to use CURL so i start this Thread.

---

there are a lot of Sample using CURL to "download" from Website or FTP but i only found this Email Sample
Code: Select all  Expand view  RUN
/* Copyright 2014-2017 Viktor Szakats */

#require "hbcurl"
#require "hbtip"

#include "simpleio.ch"
#include "hbcurl.ch"

#define HB_CURLVERINFO_VERSION                1
#define HB_CURLVERINFO_VERSION_NUM            2
#define HB_CURLVERINFO_PROTOCOLS              8  /* Array */
#define HB_CURLSSLBACKEND_SCHANNEL            8
#define HB_CURLSSLSET_OK                      0
#define HB_CURLOPT_MIMEPOST                   250

PROCEDURE Main( cFrom, cPassword, cTo, cHost )

   LOCAL lSystemCA, cCA := hb_PathJoin( iif( hb_DirBase() == "", hb_cwd(), hb_DirBase() ), "cacert.pem" )
   #if defined( __PLATFORM__WINDOWS )
   LOCAL tmp
   #endif

   LOCAL curl
   LOCAL lAPI_curl := curl_version_info()[ HB_CURLVERINFO_VERSION_NUM ] >= 0x073800

   LOCAL cUser
   LOCAL cText
   LOCAL cHTML
   LOCAL cSubject

   /* Require STARTTLS on port 587 (true) or allow it to proceed without it (false) */
   LOCAL lSTARTTLS_force

   IF hb_AScan( curl_version_info()[ HB_CURLVERINFO_PROTOCOLS ], "smtps",,, .T. ) == 0
      ? "Error: Requires libcurl 7.20.0 or newer, built with TLS/SSL and SMTP protocol support"
      RETURN
   ENDIF

   hb_default( @cFrom    , "from@example.net" )
   hb_default( @cPassword, "password" )
   hb_default( @cTo      , "to@example.org" )
   hb_default( @cHost    , "localhost" )

   cFrom := "<" + ( cUser := hb_curl_mail_address_to_email( cFrom ) ) + ">"
   cTo := "<" + hb_curl_mail_address_to_email( cTo ) + ">"
   cHost := Lower( cHost )

   cSubject := "Example sending a MIME-formatted message"

   cText := ;
      e"This is the inline text message of the email.\r\n" + ;
      e"\r\n" + ;
      e"  It could be a lot of lines that would be displayed in an email\r\n" + ;
      e"viewer that is not able to handle HTML.\r\n"

   cHTML := ;
      e"<html><body>\r\n" + ;
      e"<p>This is the inline <strong>HTML</strong> message of the email.</p>" + ;
      e"<br>\r\n" + ;
      e"<p>It could be a lot of HTML data that would be displayed by " + ;
      e"email viewers able to handle HTML.</p>" + ;
      e"</body></html>\r\n"

   lSTARTTLS_force := .F.

   /* NOTE: Consult your provider for updated settings
            and create a Pull Request if necessary. */


   DO CASE
   CASE cHost == "apple" .OR. "@icloud.com" $ cFrom .OR. "@mac.com" $ cFrom .OR. "@me.com" $ cFrom
      cHost := "smtp://smtp.mail.me.com:587"; lSTARTTLS_force := .T.
   CASE cHost == "fastmail" .OR. "@fastmail.com" $ cFrom .OR. "@fastmail.fm" $ cFrom
      cHost := "smtps://smtp.fastmail.com"
   CASE cHost == "gmx.net" .OR. "@gmx.net" $ cFrom .OR. "@gmx.ch" $ cFrom .OR. "@gmx.de" $ cFrom
      cHost := "smtps://mail.gmx.net"
   CASE cHost == "google" .OR. "@gmail.com" $ cFrom .OR. "@googlemail.com" $ cFrom
      cHost := "smtps://smtp.gmail.com"
   CASE cHost == "mail.ru" .OR. "@mail.ru" $ cFrom
      cHost := "smtps://smtp.mail.ru"
   CASE cHost == "netease" .OR. "@163.com" $ cFrom
      cHost := "smtps://smtp.163.com"
   CASE cHost == "office365"
      cHost := "smtp://smtp.office365.com:587"; lSTARTTLS_force := .T.
   CASE cHost == "outlook" .OR. "@outlook.com" $ cFrom .OR. "@hotmail.com" $ cFrom
      cHost := "smtp://smtp-mail.outlook.com:587"; lSTARTTLS_force := .T.
   CASE cHost == "sina" .OR. "@sina.com" $ cFrom
      cHost := "smtps://smtp.vip.sina.com"
   CASE cHost == "uol" .OR. "@uol.com.br" $ cFrom
      cHost := "smtps://smtps.uol.com.br"
   CASE cHost == "yahoo" .OR. "@yahoo.com" $ cFrom
      cHost := "smtps://smtp.mail.yahoo.com"
   CASE cHost == "mailtrap.io" .OR. "@mailtrap.io" $ cFrom
      cHost := "smtp://smtp.mailtrap.io:465"; lSTARTTLS_force := .T.
      cUser := StrTran( cUser, "@mailtrap.io" )
   CASE cHost == "localhost"
      cHost := "smtp://localhost:1025"  /* MailHog */
      cUser := cPassword := NIL

   CASE cHost == "securesmtp.t-online.de"
      cHost := "smtp://securesmtp.t-online.de:465"; lSTARTTLS_force := .T.

   ENDCASE

   ? "libcurl:", curl_version_info()[ HB_CURLVERINFO_VERSION ]
   ? "Payload API:", iif( lAPI_curl, "libcurl native", "tip_MailAssemble()" )
   ? "Host:", cHost, iif( lSTARTTLS_force, "(must STARTTLS)", "" )

   #if defined( __PLATFORM__UNIX )
      lSystemCA := .T.
   #elif defined( __PLATFORM__WINDOWS )
      /* Switch to SChannel SSL backend, if available (on Windows).
         Doing this to use the OS certificate store. */

      curl_global_sslset( -1,, @tmp )
      IF ( lSystemCA := ;
         HB_CURLSSLBACKEND_SCHANNEL $ tmp .AND. ;
         curl_global_sslset( HB_CURLSSLBACKEND_SCHANNEL ) == HB_CURLSSLSET_OK )
         cCA := NIL
      ELSE
         cCA := hb_DirBase() + hb_DirSepToOS( "../../../bin/" ) + cCA
      ENDIF
   #else
      lSystemCA := .F.
   #endif

   curl_global_init()

   IF Empty( curl := curl_easy_init() )
      ? "Failed to init"
   ELSE
      IF ! lSystemCA
         IF hb_vfExists( cCA )
            curl_easy_setopt( curl, HB_CURLOPT_CAINFO, cCA )
         ELSE
            ?
            ? "Error: Trusted Root Certificates missing. Open this URL in your web browser:"
            ? "  " + "https://curl.se/ca/cacert.pem"
            ? "and save the file as:"
            ? "  " + cCA
            RETURN
         ENDIF
      ENDIF
      curl_easy_setopt( curl, HB_CURLOPT_USE_SSL, ;
         iif( lSTARTTLS_force, HB_CURLUSESSL_ALL, HB_CURLUSESSL_TRY ) )
      curl_easy_setopt( curl, HB_CURLOPT_UPLOAD )
      curl_easy_setopt( curl, HB_CURLOPT_URL, cHost )
      curl_easy_setopt( curl, HB_CURLOPT_PROTOCOLS, ;
         hb_bitOr( HB_CURLPROTO_SMTPS, HB_CURLPROTO_SMTP ) )
      curl_easy_setopt( curl, HB_CURLOPT_TIMEOUT_MS, 15000 )
      curl_easy_setopt( curl, HB_CURLOPT_VERBOSE, .T. )
      curl_easy_setopt( curl, HB_CURLOPT_USERNAME, cUser )
      curl_easy_setopt( curl, HB_CURLOPT_PASSWORD, cPassword )
      curl_easy_setopt( curl, HB_CURLOPT_MAIL_FROM, cFrom )
      curl_easy_setopt( curl, HB_CURLOPT_MAIL_RCPT, { cTo } )

      IF lAPI_curl
         curl_easy_setopt( curl, HB_CURLOPT_HTTPHEADER, { ;
            "Date: " + hb_curl_date(), ;
            "To: " + cTo, ;
            "From: hbcurl " + cFrom, ;
            "Cc: " + cTo, ;
            "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>", ;
            "Reply-To: " + cFrom, ;
            "Disposition-Notification-To: " + cFrom, ;
            "X-Priority: " + hb_ntos( 3 ), ;  /* 1: high, 3: standard, 5: low */
            "Subject: " + cSubject } )

         /* NOTE: 'charset' to be added when implemented */
         curl_easy_setopt( curl, HB_CURLOPT_MIMEPOST, { ;
            { "subparts" => { ;
              { "data" => cHTML, ;
                "type" => "text/html" }, ;
              { "data" => cText } }, ;
              "type" => "multipart/alternative", ;
              "headers" => { "Content-Disposition: inline" } }, ;
            { "filedata" => __FILE__ }, ;
            { "data" => Replicate( hb_BChar( 123 ), 1024 ), ;
              "type" => "image/png", ;
              "encoder" => "base64", ;  /* binary, 8bit, 7bit, base64, quoted-printable */
              "filename" => "mock.png" } } )
      ELSE
         cText := tip_MailAssemble( ;
            "hbtip " + cFrom, ;
            { cTo }, ;
            /* aCC */, ;
            cText, ;
            cSubject, ;
            { __FILE__, { "mock.png", Replicate( hb_BChar( 123 ), 1024 ) } } /* attachments */, ;
            /* nPriority */, ;
            /* lRead */, ;
            /* cReplyTo */, ;
            /* cCharset */, ;
            /* cEncoding */, ;
            .F. /* lBodyHTML */, ;
            /* bSMIME */ )
         curl_easy_setopt( curl, HB_CURLOPT_UL_BUFF_SETUP, cText )
         curl_easy_setopt( curl, HB_CURLOPT_INFILESIZE_LARGE, hb_BLen( cText ) )
      ENDIF

      ? "Result:", curl_easy_perform( curl )
WAIT
      curl_easy_cleanup( curl )
   ENDIF

RETURN

i have "add" my Provider "T-ONLINE and it work
but it fail with my 2nd Provider WEB.DE ( missing Message-ID ? )

p.s. need OpenSSL >= v1.0.2
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Email with SSL / TLS using FiveWin

Postby NWKL » Sat Aug 13, 2022 11:29 am

Hi, can i use to send email with attachment? or have another solution working to send emails with fwh and outlook/office 365 account with attachment?

very thanks
NWKL
 
Posts: 26
Joined: Thu Aug 04, 2022 12:45 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 24 guests