E-mail support in the XFRX previewer

An email icon has been added to the XFRX previewer toolbar. It is disabled by default for backward compatibility and can be enabled by setting the iEmail property of the previewer class [xfCont, cntXFRXMultiPage or frmMPPreviewer] to 1. If you click the email icon, it runs the Email method of the xfCont class. By default it displays a simple dialog box asking for email address, subject, body, etc. and uses VFPWinsock library to send the email.


VFPWinsock is a free SMTP sendmail library written by a VFP MVP Francis Faure. It is not distributed together with XFRX and it can be downloaded from http://www.xfrx.net/vfpWinsock/index_e.asp. It is a nice little package written in VFP distributed as a single .prg.


The default behavior can be intercepted or overridden by an extension handler [Please find more information about extension handlers at 18.1.2.2 Registering an extension handler] - and, as the default dialog does not ask for all information VFPWinsock needs (eg. it does not ask for SMTP host) you actually need to create an extension handler to make it work in your environment. There are three events that extension handler can implement:

NameDescription
BeforeEmailOptions

The event is fired before the dialog is displayed and user clicked "Send".

EmailOptions

The event is fired after the dialog is displayed and user clicked "Send".

Email

The event is fired when the icon is clicked, before the dialog is displayed.

Email_BeforeTransformReport

The event is fired before calling method TransformReport().    

Email_AfterTransformReport

The event is fired after calling method TransformReport().

Email_AfterEmailedThe event is fired after e-mail was sent.


The e-mail parameter object has the following properties:

Name

TypeDescription

cSMTP_HOST

string SMTP host.

nSMTP_PORT

integerSMTP port, default value is 25.

cAUTH_Login

string

ESMTP Login.

cAUTH_Password

string ESMPT password.

cFrom

string From email address.

cFROM_Name

string From email name.

cTo

stringTo email address.

cTO_Name

string To email name.

cCC

string Carbon copy  email address.

cCC_Name

string Carbon copy  email name.

cBCC

string Blind carbon copy  email address.

cBody

string Message as text.

cBodyHTML

string Message as HTML

cDATA_MHTML 

string File name with MTH data. 

cSubject

string Subject.

cCodePage

stringCode page for subject, from name, message etc. Default value is "iso-8859-1".
But you can set "windows-1250" or "windows-1252". 
lSendbooleanSpecifies whether a XFRX call event Email or vfpWinsock.
lShowDialog boolean Specifies whether a XFRX call "E-mail options" dialog. 


Following are sample of the two most common scenarios:


Suppress the default behavior and handle the email event on your own
LOCAL m.loPreview
m.loPreview = CREATEOBJECT("frmMPPreviewer")
m.loPreview.iEmail = 1 && show the email icon
m.loPreview.oExtensionHandler = CREATEOBJECT("SampleExtensionHandler")

WITH loPreview.oEmailOptions 
.cSMTP_HOST = "mail.your_domain.com"
.cFrom = "eqeus@eqeus.com"
.cTo = "eqeus@eqeus.com"
.lShowDialog=.F. && supprisse options dialog
.lSend=.T. 
ENDWITH

m.loPreview.PreviewXFF(m.loXFF) && preview the document 

m.loPreview.show(1)
 
DEFINE CLASS SampleExtensionHandler AS CUSTOM
 
   PROCEDURE Email
      LPARAMETERS m.loXFF, m.opt[, m.oProgress]
      * loXFF - XFF file reference
      * m.opt - email options (since XFRX 17.0.0)
      * m.oProgress - XFRX progress object (since XFRX 17.0.0)

      LOCAL m.loSession, m.lcFileName
      m.loSession=EVALUATE([xfrx("XFRX#INIT")])
      m.lcFileName = Addbs(Sys(2023))+"test.pdf" && temporary file name
      IF m.loSession.SetParams(m.lcFileName,,.T.,,,,"PDF") = 0 && the 3rd parameter says we do not want to preview the PDF
         m.loSession.TransformReport(m.loXFF)
      
         LOCAL m.sm
         SET PROCEDURE TO vfpwinsock ADDITIVE 
         m.sm = Createobject("vfp_winsock_send_mail")
         m.sm.smtp_host = m.opt.cSMTP_HOST &&&<<<<<<<<<<<<<<<<<<<< put your smtp server here
         m.sm.From = m.opt.cFrom
         m.sm.To = m.opt.cTo
         m.sm.subject = "Email test"
         m.sm.silence = .T.
         m.sm.attaCHMENT = m.lcFileName
         IF !m.sm.Send()
            =MESSAGEBOX(m.sm.erreur,16,"xfrx test")
         ELSE
            =MESSAGEBOX("Message was sent",0,"xfrx test")
            ERASE (m.lcFileName)
         ENDIF
      ENDIF 
      RETURN .F.
   ENDPROC
 
ENDDEFINE

  

Use the default dialog box, use an extension handler to supply mail server parameters and let XFRX send the email
DEFINE CLASS SampleExtensionHandler AS CUSTOM
 
   PROCEDURE EmailOptions
      LPARAMETERS  m.loXFF, m.loOptions
      m.loOptions.cSMTP_HOST = "mail.your_domain.com"
      m.loOptions.cFrom = "eqeus@eqeus.com"
   ENDPROC
 
ENDDEFINE