Page 1 of 1

New Fivewin with new PDF

Posted: Sat Apr 02, 2022 8:29 am
by byron.hopp
I am testing the new Fivewin 21.11 and have been creating PDF's with the FwPdf class and it works great. Does anybody know how to be sure when the FwPdf class releases the file, or can you make sure it has released the file before moving on in the program. I am immediately needing to email the file as an attachment and need to make sure it is available before I attempt to send the email?

Thanks,

Re: New Fivewin with new PDF

Posted: Sat Apr 02, 2022 10:45 am
by cnavarro

Code: Select all | Expand


if File( "myfile.pdf" )
  ...
 

Re: New Fivewin with new PDF

Posted: Sat Apr 02, 2022 8:43 pm
by Jimmy
hi,

Code: Select all | Expand

if File( "myfile.pdf" ) .AND. FilesSire > 0

as long PDF is "not finish" Size is 0
i do have same Problem when create "ZIP" Files which work "asynchron"

Re: New Fivewin with new PDF

Posted: Sat Apr 02, 2022 9:53 pm
by cnavarro
Jimmy, yes, very good your post

Code: Select all | Expand


if File( "myfile.pdf" ) .and hb_fsize( "myfile.pdf" ) > 0   // 10
...
 

Re: New Fivewin with new PDF

Posted: Mon Apr 04, 2022 5:30 pm
by byron.hopp
All, thanks for the responses but I was hoping I could find a way to determine that the file is created and the file handle has been released with out testing for it. I have been working with PDF995 and the reason I moved to using the new fivewin was with the hope that I would not have to test for the existence of the file, test for size (and what I found out is that just not equal to zero will not work, the file may read several sizes before it is complete). Is there a way for the program to stop on the line where it is writing the file to the disc, and not move on until it is complete. Where I can be sure the file is there, complete, and released. Thanks,

Re: New Fivewin with new PDF

Posted: Mon Apr 04, 2022 6:55 pm
by karinha

Re: New Fivewin with new PDF

Posted: Mon Apr 04, 2022 8:06 pm
by Antonio Linares
Dear Byron,

You could try to rename the PDF file, as meanwhile the file is in use, you will not able to do it:

while FRename( cCurrentName, cNewName ) != 0
SysWait()
end

Re: New Fivewin with new PDF

Posted: Mon Apr 04, 2022 11:23 pm
by byron.hopp
This problem may be related to the new programming environment for my new FWHarbour libs. Is it possible that if I don't have the libs in the correct order I could have problems. I am getting the following message:

Could not send message;Error: 1;SubC: 1006;OSCode: -2147352573;SubSystem: WINOLE;Message: Argument error

This seems to happen right when I attempt to attach the file using the oEmailMsg:AddAttachment method.
If I don't include an attachment the email sends fine. Is there a way to get better information on the Argument error to help debug?

Thanks,

Re: New Fivewin with new PDF

Posted: Tue Apr 05, 2022 10:21 am
by karinha
Good Morning,

oEmailMsg:AddAttachment method


Show your email sending routine please.

test it too, with my email sending routine: RMAIL.PRG

Download Complete,

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

Use google translator to change from Portuguese to English, please.

Questions, feel free to ask.

Regards, saludos.

Re: New Fivewin with new PDF

Posted: Tue Apr 05, 2022 7:12 pm
by byron.hopp
Here is the code for email. Seems to work in xHB using FiveWin 7.01, but it doesn't work with the new FiveWin which makes me think I have something wrong with my make file.

#include "FiveWin.ch"

#DEFINE TRUE .T.
#DEFINE FALSE .F.

function Main()

TestSend()
return nil

Function TestSend()
Local cServer := "smtp.gmail.com"
Local cUserName := "Shipping@mycompany.com"
Local cPassWord := "mypassword"
Local cFrom := "Shipping@mycompany.com"
Local cSubject := DtoC( Date() ) + "-" + Time() + ", SPF Test for EMail"
Local cToAddr := "byron.hopp@gmail.com"
Local cCC := "bhopp@matrixcomputer.com"
Local cBody := "Email to test the SPF information in the EML. This email was authencated using the Shipping@mycompany.com user name."
Local cAttach := "c:\PdfFolder\Hopp.pdf"
Local cCsvFile := ""
Local lAttachCsv := FALSE
Local cLogFile := ""
McsSendEMail( cServer,cUserName,cPassWord,cFrom,cSubject,cToAddr,cCC,cBody,cAttach,cCsvFile,lAttachCsv,cLogFile )
Return nil

Function McsSendEMail( cServer,cUserName,cPassWord,cFrom,cSubject,cToAddr,cCC,cBody,cAttach,cCsvFile,lAttachCsv,cLogFile )
Local oError := nil
Local nI := 0
Local oEmailCfg := nil
Local oEmailMsg := nil
Local cHtml := '<!DOCTYPE HTML PUBLIC "-/' + '/W3C/' + '/DTD HTML 4.0 Transitional/' + '/EN">'
cHtml += '<HTML><HEAD>'
cHtml += '<META content="text/html; charset=iso-8859-1" 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 face=Courier New>' + cBody + '</FONT></DIV></BODY></HTML>'

Try
oEmailCfg := CreateObject("CDO.Configuration")
oEmailCfg:Fields:Item( "http:" + "/" + "/" + "schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := cServer // "smtp.gmail.com"
oEmailCfg:Fields:Item( "http:" + "/" + "/" + "schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := 465 // was 587
oEmailCfg:Fields:Item( "http:" + "/" + "/" + "schemas.microsoft.com/cdo/configuration/sendusing" ):Value := 2 // 1 Pickup, 2 Port, 3 Exchange
oEmailCfg:Fields:Item( "http:" + "/" + "/" + "schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := TRUE
oEmailCfg:Fields:Item( "http:" + "/" + "/" + "schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value := TRUE // FALSE
oEmailCfg:Fields:Item( "http:" + "/" + "/" + "schemas.microsoft.com/cdo/configuration/sendusername" ):Value := cUserName
oEmailCfg:Fields:Item( "http:" + "/" + "/" + "schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := cPassWord
oEmailCfg:Fields:Item( "http:" + "/" + "/" + "schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout" ):Value := 10

oEmailCfg:Fields:Update()
Catch oError
MsgStop( oError:Description,"CDO.Configuration - cEMailCfg:Fields:Update()")
End Try
Try
oEmailMsg := CreateObject("CDO.Message")
oEmailMsg:Configuration := oEmailCfg
oEmailMsg:From := cFrom // chr(34) + "shipping@mycompany.com" + chr(34) + "<shipping@mycompany.com>"
oEmailMsg:To := cToAddr // "bhopp@matrixcomputer.com"
oEmailMsg:Cc := ""
oEmailMsg:BCc := ""
oEmailMsg:Subject := cSubject
oEmailMsg:MDNRequested := FALSE
oEmailMsg:HTMLBody := cBody

If File( cAttach )
oEmailMsg:AddAttachment := cAttach
Endif

If lAttachCsv .AND. File( cCsvFile )
oEmailMsg:AddAttachment := cCsvFile
Endif

oEmailMsg:Send()
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 Try
Return nil

Re: New Fivewin with new PDF

Posted: Tue Apr 05, 2022 7:20 pm
by karinha
Byron, test your modified example now.

Code: Select all | Expand


// ** Test program for email *** version by kapiabafwh@gmail.com

#include "FiveWin.ch"

FUNCTION Main()

   TestSend()

RETURN NIL

FUNCTION TestSend()

   /*
   LOCAL cServer := "smtp.gmail.com"
   LOCAL cUserName := "Shipping@mycompany.com"
   LOCAL cPassWord := "MyPassword"
   LOCAL cFrom := "Shipping@mycompany.com"
   LOCAL cSubject := DToC( Date() ) + "-" + Time() + ", Test for EMail"
   LOCAL cToAddr := "byron.hopp@gmail.com"
   LOCAL cCC := "bhopp@matrixcomputer.com"
   LOCAL cBody := "Email to test the SPF information in the EML. This email was authencated using the Shipping@mycompany.com user name."
   LOCAL cAttach := "c:\PdfFolder\Hopp.pdf" // any pdf can go here
   LOCAL cCsvFile := ""
   LOCAL lAttachCsv := .F.
   LOCAL cLogFile := ""
   */


   // It worked perfect Byron.
   LOCAL cServer    := "smtp.pleno.com.br"
   LOCAL cUserName  := "joao@pleno.com.br"
   LOCAL cPassWord  := "MyPassword"
   LOCAL cFrom      := "joao@pleno.com.br"
   LOCAL cSubject   := DToC( Date() ) + "-" + Time() + ", Test for EMail"
   LOCAL cToAddr    := "kapiabafwh@gmail.com"
   LOCAL cCC        := "bhopp@matrixcomputer.com"
   LOCAL cBcc       := "joao@pleno.com.br"
   LOCAL cBody      := "Body Byron: Email to test the SPF information in the EML. This email was authencated using the Shipping@mycompany.com user name."
// LOCAL cAttach    := "c:\PdfFolder\Hopp.pdf" // any pdf can go here
   LOCAL cAttach    := "C:\ORCAMPDF\INSUMOS.PDF"
   LOCAL cCsvFile   := ""
   LOCAL lAttachCsv := .F.
   LOCAL cLogFile   := ""

   IF .NOT. FILE( cAttach )

      MsgInfo( "Warning: PDF file, not located in source folder.", ;
               "Warning: PDF file, not located in source folder." )

   ENDIF

   McsSendEMail( cServer, cUserName, cPassWord, cFrom, cSubject, cToAddr, cCC, cBcc, cBody, cAttach, cCsvFile, lAttachCsv, cLogFile )

RETURN NIL

FUNCTION McsSendEMail( cServer, cUserName, cPassWord, cFrom, cSubject, cToAddr, cCC, cBcc, cBody, cAttach, cCsvFile, lAttachCsv, cLogFile )

   LOCAL oError, oCfg, oMsg, lRet := .T.
   LOCAL cHtml := '<!DOCTYPE HTML PUBLIC "-/' + '/W3C/' + '/DTD HTML 4.0 Transitional/' + '/EN">'

   cHtml += '<HTML><HEAD>'
   cHtml += '<META content="text/html; charset=iso-8859-1" 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 face=Courier New>' + cBody + '</FONT></DIV></BODY></HTML>'

   /* // ??? Internal ???
   IF Upper( AllTrim( cServer ) ) <> "smtp.gmail.com" .OR. ;
      Upper( AllTrim( cUserName ) ) <> "shipping@frupco.com" .OR. ;
      AllTrim( cPassWord ) <> "sC-93611"

      MsgStop( "Please check the Email Credentials in the INI file, or call MCS.", "McsSendEmail" )

      RETURN NIL

   ENDIF
   */


   Try

      oCfg := CreateObject( "CDO.Configuration" )

      WITH OBJECT oCfg:Fields

         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver"       ):Value := cServer // Servidor SMTP
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport"   ):Value := 587     // nPort
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing"        ):Value := 2       // Remote SMTP = 2, local = 1
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := .T.     // lAut
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl"       ):Value := .F.     // lSSL // .F. Ou .T.
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername"     ):Value := TRIM(cUserName)
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword"     ):Value := TRIM(cPassWord)
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 60

         oCfg:Update()

      END WITH

   Catch oError

      MsgStop( oError:Description, "CDO.Configuration - cEMailCfg:Fields:Update()" )

   End Try

   Try

      oMsg := CREATEOBJECT ( "CDO.Message" )

      WITH OBJECT oMsg

         oMsg:Configuration := oCfg
         oMsg:FROM          := cFrom // chr(34) + "shipping@mycompany.com" + chr(34) + "<shipping@mycompany.com>"
         oMsg:TO            := cToAddr // "bhopp@matrixcomputer.com"
         oMsg:Cc            := cCC //""
         oMsg:BCc           := cBcc //""
         oMsg:Subject       := cSubject
         oMsg:MDNRequested  := .F.
         oMsg:HTMLBody      := cBody

      IF File( cAttach )

         oMsg:AddAttachment := cAttach

      ENDIF

      IF lAttachCsv .AND. File( cCsvFile )

         oMsg:AddAttachment := cCsvFile

      ENDIF

      :Send()

      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 )

      lRet := .F.

   End Try

   IF lRet

     MsgInfo( "Message sent successfully. Congratulations.", ;
              "Message sent successfully. Congratulations."  )


   ENDIF

   oCfg := Nil
   oMsg := Nil

RETURN NIL

// fin / end - 05/04/2022 - kapiabafwh@gmail.com - Covid-19
 


Regards, saludos.

Re: New Fivewin with new PDF

Posted: Tue Apr 05, 2022 7:30 pm
by karinha
Byron, don't forget that starting in May, gmail.com will be disabled for less secure APPs.

Regards, saludos.

Re: New Fivewin with new PDF

Posted: Wed Apr 06, 2022 11:44 am
by karinha

Code: Select all | Expand


// \samples\BYRON.PRG  using gmail.com -> worked perfect

// ** Test program for email *** version by kapiabafwh@gmail.com

#include "FiveWin.ch"

FUNCTION Main()

   SET CENTURY ON
   SET DATE BRITISH

   TestSend()

RETURN NIL

FUNCTION TestSend()

   /*
   LOCAL cServer := "smtp.gmail.com"
   LOCAL cUserName := "Shipping@mycompany.com"
   LOCAL cPassWord := "MyPassword"
   LOCAL cFrom := "Shipping@mycompany.com"
   LOCAL cSubject := DToC( Date() ) + "-" + Time() + ", Test for EMail"
   LOCAL cToAddr := "byron.hopp@gmail.com"
   LOCAL cCC := "bhopp@matrixcomputer.com"
   LOCAL cBody := "Email to test the SPF information in the EML. This email was authencated using the Shipping@mycompany.com user name."
   LOCAL cAttach := "c:\PdfFolder\Hopp.pdf" // any pdf can go here
   LOCAL cCsvFile := ""
   LOCAL lAttachCsv := .F.
   LOCAL cLogFile := ""
   */


   // It worked perfect Byron. Using: gmail.com
                                   // nPort:   SSL
   //  {"@gmail.com", "smtp.gmail.com", 465,   .T. },;
   LOCAL cServer    := "smtp.gmail.com"
   LOCAL cUserName  := "kapiabafwh@gmail.com"
   LOCAL cPassWord  := "mylongpassword"
   LOCAL cFrom      := "kapiabafwh@gmail.com"
   LOCAL cSubject   := DToC( Date() ) + "-" + Time() + ", Test for EMail"
   LOCAL cToAddr    := "kapiabafwh@gmail.com"
   LOCAL cCC        := "bhopp@matrixcomputer.com"
   LOCAL cBcc       := "joao@pleno.com.br"
   LOCAL cBody      := "Byron Using GMAIL.COM: Email to test the SPF information in the EML. This email was authencated using the Shipping@mycompany.com user name."
// LOCAL cAttach    := "c:\PdfFolder\Hopp.pdf" // any pdf can go here
   LOCAL cAttach    := "C:\ORCAMPDF\INSUMOS.PDF"
   LOCAL cCsvFile   := ""
   LOCAL lAttachCsv := .F.
   LOCAL cLogFile   := ""

   IF .NOT. FILE( cAttach )

      MsgInfo( "Warning: PDF file, not located in source folder.", ;
               "Warning: PDF file, not located in source folder." )

   ENDIF



   McsSendEMail( cServer, cUserName, cPassWord, cFrom, cSubject, cToAddr, cCC, cBcc, cBody, cAttach, cCsvFile, lAttachCsv, cLogFile )

RETURN NIL

FUNCTION McsSendEMail( cServer, cUserName, cPassWord, cFrom, cSubject, cToAddr, cCC, cBcc, cBody, cAttach, cCsvFile, lAttachCsv, cLogFile )

   LOCAL oError, oCfg, oMsg, lRet := .T.
   LOCAL cHtml := '<!DOCTYPE HTML PUBLIC "-/' + '/W3C/' + '/DTD HTML 4.0 Transitional/' + '/EN">'

   cHtml += '<HTML><HEAD>'
   cHtml += '<META content="text/html; charset=iso-8859-1" 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 face=Courier New>' + cBody + '</FONT></DIV></BODY></HTML>'

   /* // ??? Internal ???
   IF Upper( AllTrim( cServer ) ) <> "smtp.gmail.com" .OR. ;
      Upper( AllTrim( cUserName ) ) <> "shipping@frupco.com" .OR. ;
      AllTrim( cPassWord ) <> "sC-93611"

      MsgStop( "Please check the Email Credentials in the INI file, or call MCS.", "McsSendEmail" )

      RETURN NIL

   ENDIF
   */


   Try

      oCfg := CreateObject( "CDO.Configuration" )

      WITH OBJECT oCfg:Fields

         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver"       ):Value := cServer // Servidor SMTP
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport"   ):Value := 465 //<-(gmail)   587     // nPort
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing"        ):Value := 2       // Remote SMTP = 2, local = 1
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := .T.     // lAut
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl"       ):Value := .T.     // lSSL // .F. Ou .T.(gmail)
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername"     ):Value := TRIM(cUserName)
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword"     ):Value := TRIM(cPassWord)
         oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 60

         oCfg:Update()

      END WITH

   Catch oError

      MsgStop( oError:Description, "CDO.Configuration - cEMailCfg:Fields:Update()" )

   End Try

   Try

      oMsg := CREATEOBJECT ( "CDO.Message" )

      WITH OBJECT oMsg

         oMsg:Configuration := oCfg
         oMsg:FROM          := cFrom // chr(34) + "shipping@mycompany.com" + chr(34) + "<shipping@mycompany.com>"
         oMsg:TO            := cToAddr // "bhopp@matrixcomputer.com"
         oMsg:Cc            := cCC //""
         oMsg:BCc           := cBcc //""
         oMsg:Subject       := cSubject
         oMsg:MDNRequested  := .F.
         oMsg:HTMLBody      := cBody

      IF File( cAttach )

         oMsg:AddAttachment := cAttach

      ENDIF

      IF lAttachCsv .AND. File( cCsvFile )

         oMsg:AddAttachment := cCsvFile

      ENDIF

      :Send()

      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 )

      lRet := .F.

   End Try

   IF lRet

     MsgInfo( "Message sent successfully. Congratulations.", ;
              "Message sent successfully. Congratulations."  )


   ENDIF

   oCfg := Nil
   oMsg := Nil

RETURN NIL

// fin / end - 06/04/2022 - kapiabfwhgmail.com - Covid-19
 


Regards, saludos.