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"