Send mail from fastreport

Send mail from fastreport

Postby mtajkov » Sun Nov 26, 2023 3: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.

Image

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

Image


This is code:

Code: Select all  Expand view


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) ]
mtajkov
 
Posts: 130
Joined: Sun Mar 08, 2009 4:33 pm

Re: Send mail from fastreport

Postby karinha » Wed Nov 29, 2023 5:59 pm

Have you tried like this?

Code: Select all  Expand view


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
User avatar
karinha
 
Posts: 7805
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 79 guests