by Marco Turco » Sat Aug 29, 2009 3:05 pm
Hi,
you can send a report via email using the standard FR mailsender. The big problem of this solution is that it requires the mail account (userid,password, smtp account etc) so I think it is a little complex for the end-use. See FRH manual for a sample.
I personally suggest you to use a more user-friendly solution as an ole connection to Outlook / MAPI in order FR simply open an email with the attachment directly in Outlook or into a MAPI compatible client.
you can make this adding this code at the end of the report
..
..
FrPrn:SetProperty("MailExport","ShowDialog",.f.)
FrPrn:SetEventHandler("MailExport","OnSendMail",{|ParamsArray|MySendMail(FrPrn,cPdfFile)})
..
and with these functions
Function MySendMail(FrPrn,cFile)
local aFiles
FrPrn:SetProperty("PDFExport","OpenAfterExport",.f.)
FrPrn:SetProperty("PDFExport", "ShowDialog", .f.)
FrPrn:SetProperty("PDFExport", "EmbeddedFonts", .f.)
FrPrn:SetProperty("PDFExport", "PrintOptimized", .t.)
FrPrn:DoExport("PDFExport")
aFiles:={}
aadd(aFiles,{cFile,cFile})
InteractiveMessage("","","",aFiles,.f.)
return("")
FUNCTION Interactivemessage()
paramet cSubject, cBody, aTo, aFiles, lDirectSend
LOCAL oOutLook,oMailItem,oRecip,oAttach,i,lOffice,lMailMancante
if lDirectSend=NIL
lDirectSend:=.f.
endif
if cSubject=NIL
cSubject:=""
endif
if cBody=NIL
cBody:=""
endif
if aFiles=NIL
aFiles:=array(0,0)
endif
lMailMancante:=.f.
for i:=1 to len(aTo)
if len(alltrim(aTo[i,2]))=0
lMailMancante:=.t.
endif
next
if lMailMancante
MsgStop("Indirizzo di posta elettronica assente","Attenzione")
return
endif
lOffice:=.t.
TRY
oOutLook := CreateObject( "Outlook.Application" )
oMailItem := oOutLook:CreateItem( 0 )
oRecip := oMailItem:Recipients
CATCH
lOffice:=.f.
END
if lOffice
for i:=1 to len(aTo)
oRecip:Add( aTo[i,2] )
next
oMailItem:Subject := cSubject
oMailItem:Body := cBody
if len(aFiles)>0
oAttach := oMailItem:Attachments
for i:=1 to len(aFiles)
oAttach:Add( aFiles[i,1] )
next
endif
if lDirectSend
oMailItem:Send()
else
oMailItem:display(.t.)
endif
else
for i:=1 to len(aTo)
aTo[i,1]:=alltrim(aTo[i,2])
aTo[i,2]:=alltrim(aTo[i,2])
next
oMail:=tMail():New( cSubject,cBody,,,,, .f., .t.,,aTo,aFiles)
ACTIVATE MAIL oMail
retcode:=oMail:nRetCode
endif
return
Best Regards,
Marco Turco
SOFTWARE XP LLP