FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Send mail from fastreport
Posts: 130
Joined: Sun Mar 08, 2009 04:33 PM
Send mail from fastreport
Posted: Sun Nov 26, 2023 03:57 AM
I am sending mail from Fastreport so that the "Export to PDF" dialog does not open. When executing the command FrPrn:DoExport("PDFExport"), the report disappears from the screen and Outlook opens. As long as Outlook is open, the report is not visible on the screen.



I want it to behave like when using the "Export to pdf" dialog (FrPrn:SetProperty("PDFExport", "ShowDialog", .t.)):




This is code:
Code (fw): Select all Collapse
Function PdfAndMail(mSubject,mTo,mCc)

mFileName=cOsnDir+"\Pdf\" + rtrim(mSubject) + ".pdf"


   FrPrn:SetProperty("PDFExport", "Title", mSubject)
   FrPrn:SetProperty("PDFExport", "Author", mKorisnik)
   FrPrn:SetProperty("PDFExport", "Subject", RptHead->Naziv)

   FrPrn:SetProperty("PDFExport", "FileName", mFileName)
   FrPrn:SetProperty("PDFExport", "OpenAfterExport", .t.)
   FrPrn:SetProperty("PDFExport", "ShowDialog", .t.)
   FrPrn:SetProperty("PDFExport", "PrintOptimized", .t.)
   FrPrn:PrepareReport()
   

   FrPrn:SetProperty("MailExport", "ShowExportDialog", .f.)
   FrPrn:SetProperty("MailExport", "ShowDialog",.f.)

   FrPrn:SetEventHandler("MailExport","OnSendMail",{|ParamsArray|MySendMail(mSubject,mTextBody,mTo,mCc,mFileName,.f.,FrPrn)})


   FrPrn:ShowReport()
   FrPrn:DestroyFR()

function MySendMail()

paramet cSubject, cBody, aTo, aCc, aFiles, lDirectSend, oFrPrn

LOCAL cTasks,oAttach

LOCAL OutlFound := .F.

FrPrn:SetProperty("PDFExport","OpenAfterExport",.f.)
FrPrn:SetProperty("PDFExport", "ShowDialog", .f.)
FrPrn:DoExport("PDFExport")

cTasks := GetTasks()
FOR i=1 TO LEN(cTasks)
    IF AT("OUTLOOK",UPPER(cTasks[i])) <> 0
       OutlFound := .T.
       i := LEN(cTasks)
    ENDIF
NEXT
IF !OutlFound ; ShellExecute(,"Open","Outlook",,,1) ; ENDIF

TRY
   oOutLook   := CreateObject("Outlook.Application")
   oNameSpace := oOutlook:GetNameSpace("MAPI")
   EmSend     := .T.
CATCH
   TRY
      oOutLook   := CreateObject("Outlook.Application")
      oNameSpace := oOutlook:GetNameSpace("MAPI")
      EmSend     := .T.
   CATCH
      EmSend   := .F.
   END
END

IF EmSend

oMail := oOutLook:CreateItem(0)
oMail:Subject := cSubject
oMail:Body := cBody
oMail:To := aTo
oMail:CC := aCc
oMail:BCC := ""

oAttach := oMail:Attachments
oAttach:Add(aFiles)
oMail:Display = .T.
*oMail:Send()

ENDIF

   FrPrn:SetProperty("PDFExport", "OpenAfterExport", .t.)
   FrPrn:SetProperty("PDFExport", "ShowDialog", .t.)

Return ("")
Best regards

Milos



[ FWH 21.11 ] [ xHarbour 1.2.3 Intl. (SimpLex) (Build 20150603) ]
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Send mail from fastreport
Posted: Wed Nov 29, 2023 05:59 PM
Have you tried like this?
Code (fw): Select all Collapse
oFrPrn:SetProperty("PDFExport", "OpenAfterExport", .t.)


oFrPrn:SetEventHandler("MailExport", "OnSendMail", {|| OPCOES_FAST_PREVIEW(oFrPrn, nBOLETO, cENTSAI, cEMAIL_DIRETO,cREL) })

FUNCTION OPCOES_FAST_PREVIEW()
....aqui vai sua tela de envio de email
RETURN(.T.)
https://sagierp.com.br/devel/fastreport/manual_xHarbour_fastreport.pdf

https://github.com/EduardoSP6/Fast_Report/blob/master/Fast%20Report/__history/DEMO_FWH.prg.~2~

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341

Continue the discussion