2024-05-21

FoxyPreviewer 3 - Sending E-mails

 FoxyPreviewer brings 5 ways for you to send emails:

1 – MAPI - Uses the WinAPI MapiSendMail to try to send the current report as an attachment.
This setting sends a standard message, with one or more attached files and a cover note. The cover note is a dialog box that allows the user to enter a list of recipients and an optional message and other sending options. It will open a dialog email sending message, waiting for a user interaction. The message will not be sent automatically. It’s up to the user to veryfy the information ofthe message and to click at the “Send” button. 
This function tries to establish a session using the messaging system's shared session. If no shared session exists, it will fail sending the message.
This works pretty well if you have your default account set using MS Outlook Express, MS Outlook or Windows Live Mail. Definitely, it’s the easiest way to send your messages, because this way, FoxyPreviewer will use the default Email configuration of the computer.

You can set this mode by:

_Screen.oFoxyPreviewer.nEmailMode = 1 && MAPI


2 - MAPI Alternative – Uses the WinAPI MapiSendDocuments to try to send the current report as an attachment.
The MAPISendDocuments function sends a standard message with one or more attached files and a cover note. The cover note is a dialog box that allows the user to enter a list of recipients and an optional message and other sending options.
This function tries to establish a session using the messaging system's shared session. If no shared session exists, it will fail sending the message.
This works pretty well if you have your default account set using MS Outlook Express, MS Outlook or Windows Live Mail. Definitely, it’s the easiest way to send your messages, because this way, FoxyPreviewer will use the default Email configuration of the computer.
Although MS says that “The use of this function is discouraged. It may be altered or unavailable in subsequent versions of Windows.”, it’s been working well in all OS’s, from WinNT to WinSeven


_Screen
.oFoxyPreviewer.nEmailMode = 5 && MAPI Alternative


3 – Custom Procedure
You can use your own procedure to send the current report. use foxypreviewer property "cEmailPrg", and fill it with the name of the prg responsible for sending emails. This PRG receives as a parameter the file name of the file created that you will send as attachment. Have a look at the samples provided, the file MYSENDMAIL.PRG shows how you would need to make your custom procedure. The idea is that when your user clicks in the "Sent to E-mail" button from the Preview, the generated output file will be sent using your own pocedure.

* THIS BRINGS YOU AN OPTION TO CONTROL WHAT FUNCTIONS EACH USER WILL HAVE AVAILABLE
WITH _Screen.oFoxyPreviewer
    .cEmailPrg = "MYSENDMAIL.PRG" && This is your PRG with your custom procedure
    .nEmailMode = 4 && CUSTOM PROCEDURE
    .cEmailType  = "PDF"   
ENDWITH

REPORT FORM (_Samples + "\Solution\Reports\percent.frx") PREVIEW

Then, in your PRG - AKA "MYSENDMAIL.PRG", add in the 1st line:

LPARAMETERS tcFileToSend


And add all code you need to send your messages the way you need.

 

4 – CDO
Uses the CDO2000 component included in windows 2000 and later. It allows you to send emails using a SMTP server. All settings must be accurate in order to make this work. 

The usage was really simple, but it's not compatible with TLS - evolved from the good and old SSL protocol, providing more security to the process. That means that the main SMTP servers are not compatible with it any more - Outlook.com and Gmail.com use the Port 587 that is not supported. But This way to send mails is still valid for several other E-mail servers.

 

5 – POWERSCRIPT MAIL
Uses PowerScript to access the "SendMail-Message" function from .NET
This is a very nice, up to date way to send your e-mails. The best is that it is compatible with all e-mail servers and Smtp ports.

_Screen.oFoxyPreviewer.nEmailMode = 7 && Powerscript mail

The easiest way to configure your e-mails is from the settings form from the Preview Screen:

You can set all properties, and even test your SMTP server settings, in CDO or Powerscript to be sure they work!

Below is a short animation showing dynamically how it works. Once you set them, the same settings will be available for the next reports!

 


Of course you can set it all programatically as well! See:

WITH _SCREEN.oFoxyPreviewer
	.cEmailPRG 		= "MySendPSEmail2.PRG"
	.nEmailMode     = 7     && 1 = MAPI, 2 = CDOSYS HTML, 3 = CDOSYS TEXT, 4 = Custom procedure, 6=CustomProc 7=Powerscript
	.cEmailTo       = "destination@hotmail.com"
	.cEmailFrom     = "you@hotmail.com"
	.cEmailSubject  = "Subject test"
	.nSMTPPort      = 587 && TLS
	.lSMTPUseSSL    = .T.
	.cSMTPUserName  = .cEmailFrom
	.cSMTPServer    = "smtp.office365.com"
	.cSMTPPassword  = "yourpwd"
	.lEmailAuto     = .T.   && Automatically generates the report output file
	.cEmailType     = "PDF" && The file type to be used in Emails (PDF, RTF, HTML or XLS)
	.cEmailBody     = "<BR>Email Test with <b>FoxyPreviewer</b>"
ENDWITH

REPORT FORM (_Samples + "\Solution\Reports\percent.frx") PREVIEW


And finally, here are the E-mail properties that you can set in FoxyPreviewer3:


Generic Email settings

  •  nEmailMode - numeric, the email type (1 = MAPI, 2 = CDOSYS HTML, 3 = CDOSYS TEXT, 4 = Custom procedure)
  •  lEmailAuto - logical, Automatically generates the report output file. The file name to be used is determined by the property "cSaveDefName".
  •  cEmailType - character, the file type to be used in Emails (PDF, RTF, HTML or XLS)
  •  cEmailPRG - character, the name of a PRG that will fire your custom email. In this PRG, you need to receive one parameter, tcFiIle, that is the temporary output file that you'll send by email. A complete sample, "MYSENDMAIL.PRG" is available, showing you how you can send your emails. To use it, you need to set the value of this property, for instance: .cEmailPrg = "MySendMail.Prg"
  •  cSaveDefName - character, the default name of the save file. Available in the SAVE AS dialog OR automatically used if lEmailAuto
  •  cTempDestFile - character, the temporary destination file (image, htm, pdf, etc). Its contents will be wiped after the 1st report run. That means that the default file name will return to be empty after the report run. (FPv3)
     cFaxPRG - character, the custom procedure name responsible for sending faxes. For example: _Screen.oFoxyPreviewer.cFaxPrg = "mySendFax.prg"

CDOSYS EMAIL PROPERTIES
  •  cSMTPServer - character, the SMTP server address. Applicable when ".nEmailMode=2 or 3"
  •  nSMTPPort - numeric, the SMTP port (usually 25). Applicable when ".nEmailMode=2 or 3"
  •  lSMTPUseSSL - logical, determines if the SMTP server requires SSL (security connection). Applicable when ".nEmailMode=2 or 3"
  •  cSMTPUserName - character, the SMTP user name. Applicable when ".nEmailMode=2 or 3"
  •  cSMTPPassword - character, the SMTP password. Applicable when ".nEmailMode=2 or 3"
  •  cEmailTo - character, the destination email. You may use the comma "," separator to use more than one address
  •  cEmailCC - character, the destination COPY email. You may use the comma "," separator to use more than one address. Applicable when ".nEmailMode=2 or 3"
  •  cEmailBCC - character, the destination BLIND COPY email. You may use the comma "," separator to use more than one address. Applicable when ".nEmailMode=2 or 3"
  •  cEmailReplyTo - character, the email to be used for replies. Applicable when ".nEmailMode=2 or 3"
  •  cEmailSubject - character, the email subject. Applicable when ".nEmailMode=2 or 3"
  •  cEmailBody - character, the email text body. Applicable when ".nEmailMode=2 or 3"
  •  cEmailFrom - character, the email sender information. You may add some custom captions, eg: 'FoxyPreviewer team<foxyteam@hotmail.com>'. Applicable when ".nEmailMode=2 or 3"
  •  cEmailBodyFile - character, the HTML file to be used as email body. Applicable when ".nEmailMode=2 or 3"
  •  lReadReceipt - logical, determines if the message will ask for a read receipt. Applicable when ".nEmailMode=2 or 3"
  •  lPriority - logical, determines if the priority level will be high. Applicable when ".nEmailMode=2 or 3"
  •  cEncryptProcedure - character, The programmer can apply his own Scrambling method on the password string (for advanced users). Applicable when ".nEmailMode=2 or 3"
  •  cDecryptProcedure - character, The programmer can apply his own Scrambling method on the password string (for advanced users). Applicable when ".nEmailMode=2 or 3"
  •  cCryptKey - character, the crypt key used to encrypt the SMTP password stored in the settings table (for advanced users). Applicable when ".nEmailMode=2 or 3"
  •  cAttachments - character, the fullpath of the files to be attached to the email message. Use a comma "," as a delimiter between files (for advanced users). Applicable when ".nEmailMode=2 or 3"
  •  cAdressTable - character, the name of the alias or FullPath of a table that contains an adress book with emails to be used when sending email messages using the provided form. This table MUST contain a Field of Character type, named "email". Apart from that, it can contain any other data that you want to be visible in a search grid, helping the users to choose the destination. For a better comprehension, please refer to the samples provided and the FAQS. (for advanced users). Applicable when ".nEmailMode=2 or 3"
  •  cAdressSearch - character, optional, the name of the field to be used for making searches. (for advanced users). Applicable when ".nEmailMode=2 or 3"






 

2024-02-06

WIN32API - How to know if the printer has Duplex capabilities



******************************************************************** FUNCTION PR_IsDuplex LPARAMETERS m.tcPrinter ******************************************************************** #DEFINE DC_DUPLEX 7 *!* * https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-devicecapabilitiesa *!* int DeviceCapabilitiesA( *!* [in] LPCSTR pDevice, *!* [in] LPCSTR pPort, *!* [in] WORD fwCapability, *!* [out] LPSTR pOutput, *!* [in] const DEVMODEA *pDevMode *!* ) * DC_DUPLEX * If the printer supports duplex printing, the return value is 1; otherwise, the return value is zero. * The pOutput parameter is not used. LOCAL lnDuplex, llIsDuplex DECLARE Long DeviceCapabilities IN winspool.drv as xfcDeviceCapabilities ; String pDevice, String pPort, Long fwCapability, ; String @pOutput, Long pDevMode TRY m.lnDuplex = xfcDeviceCapabilities(m.tcPrinter, "", DC_DUPLEX, "", 0) m.llIsDuplex = IIF(lnDuplex = 1, .T., .F.) CATCH TO m.loExc m.llIsDuplex = .F. ENDTRY RETURN m.llIsDuplex ENDFUNC


2023-04-16

Capture Form portions - FoxyCapture

Recently Tom Knauf from Germany asked for a feature in FoxyPreviewer3 to allow users to pick specific parts of their reports and export them to the clipboard or save as image in an easy way.

Nothing new on this, I even published about 10 years ago a solution for that, but it was not working anymore.

So, I took the opportunity to create it from scratch, but this time thinking of a good way to make it work safely with FoxyPreviewer3.

FOXYCAPTURE is a custom VFP class that you can toss in any VFP form.

To activate it, just call the method "StartCapture", and select the rectangle portion of your form you's like to capture. After dragging, a shortcut menu will allow you to either save as PNG or send the image to the clipboard.

Source code and a sample form included, please let me know if you find any issues or make any improvements.

Below some animated images showing how it works.


Picture1 - Capture to image file



Picture2 - Capture image to the clipboard, and paste it to WhatsApp web:


Files to include in your project:

  • FoxyCapture.vcx
  • FoxyCapture.vct
  • fc_Save.Bmp
  • fc_Clipboard.bmp


Related Methods / Properties

Method:

StartCapture - Starts capturing the mouse events to capture the form surface


Properties:

BorderColor - Numeric, the RGB value of the border color to drawn to determine the rectangle to be captured

ShowBorder - Logical, determines if the dotted shape borders will appear in the captured image or not


Download link:

LATEST UPDATES

- 2023-04-22 v1.04 - Now instead of trying to bind all the form objects it draws an invisible container on the screen, where the dotted rectangle used for selecting the screen contents is drawn.
This brought the advantage of allowing to select any part of the form, Grids, PageFrames, Textboxes, etc, without the need of Disabling objects. Forms with grids are working fine as well.


2022-10-13

FoxyPreviewer3 and its files

FoxyPreviewer3 needs to create several files in order to run, so here I will explain what happens behind the scenes, so that people can get the most benefit from it.

Initilization
At initialization, FP search for 2 files - if not found it will restore from the embedded app
 - LibHaru.dll - the PDF engine created by Takeshi Kano, that is used to generate PDFfiles using ".nPDFType=1". This file will be stored at the same folder that FoxyPreviewer.App resides.
 - FoxyPreviewer_Settings.dbf - stores the user customized settings. This table can be edited as you like. Whenever a user changes an option in the settings screen it gets updated, and it will be loaded at initialization. This file will be recreated if you delete it.

Folders
Also at initialization 3 folders will be created:
 - \FP_IMAGES - Here all the images used for creating the toolbar buttons will reside. FP3 will restore them from the APP, and whenever you or your users change the button colors or behaviors, the new images created will be stored there. If you open that folder, you'll see all buttons that you used previously. The images are stored there physically so that in the next run they wont need to be recreated. All buttons, the original, the new "font based" buttons need some GDI+ processing, and some users could not like the delay needed to recreate them at each run. If you remove any image, or even the whole folder FP3 will recreate it on the next run.

FoxyPreviewer3 and sending e-mails

FoxyPreviewer3 - Getting support

When asking for support for FoxyPreviewer, to help me reproducing your environment, please immediately after your issue execute the following line of code:

_Screen.oFoxyPreviewer.GetFoxyScript()





This will create a script that will help me to mimic partially your environment, so that I can reproduce what is happening at your side.

Please revise that file, erase any data that you feel is sensitive and send it for support.


2022-10-06

FoxyPreviewer3 and localization strings

FoxyPreviewer's default language is English.

Right now there is suport to 22 languages: English, Portuguese, Spanish, French, German, Greek, Turkish, Czech, Persian, Arabic, Italian, Indonesian, Polish, Swahili, Russian , Simplified Chinese , Traditional Chinese , Dutch, Bulgarian, Hungarian, Kazakh and Serbian.

Special tweaks were applied to allow double-byte languages, such as Chinese and Japanese.


To change the default language there are 2 options:

1 - Setting the _Screen.oFoxyPreviewer object, by passing  pass the English language name or the local language name - for instance, to change the language to French or spanish:

_Screen.oFoxyPreviewer.cLanguage = "SPANISH"  && or
_Screen.oFoxyPreviewer.cLanguage = "ESPANIOL"

_Screen.oFoxyPreviewer.cLanguage = "FRENCH"   && or
_Screen.oFoxyPreviewer.cLanguage = "FRANÇAIS"

2 - Users can change by themselves to their desired language in the Settings form:



Some of the languages are not updated. FP3 brings new facilities and dialogs that still need to be updated.. 

If you're interested, please download the Localizations table from the link below and send it back to vfpimaging at hotmail dot com

I'll be happy to update the localizations table in the future updates.