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.
Name | Description |
---|---|
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". |
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_AfterEmailed | The event is fired after e-mail was sent. |
The e-mail parameter object has the following properties:
Name | Type | Description |
---|---|---|
string | SMTP host. | |
integer | SMTP port, default value is 25. | |
string | ESMTP Login. | |
string | ESMPT password. | |
string | From email address. | |
string | From email name. | |
string | To email address. | |
string | To email name. | |
string | Carbon copy email address. | |
string | Carbon copy email name. | |
string | Blind carbon copy email address. | |
string | Message as text. | |
string | Message as HTML | |
string | File name with MTH data. | |
string | Subject. | |
string | Code page for subject, from name, message etc. Default value is "iso-8859-1". But you can set "windows-1250" or "windows-1252". | |
lSend | boolean | Specifies 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:
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
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