Page 1 of 1

Send mail from fastreport

Posted: Sun Nov 26, 2023 3:57 am
by mtajkov
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


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 ("")


Re: Send mail from fastreport

Posted: Wed Nov 29, 2023 5:59 pm
by karinha
Have you tried like this?

Code: Select all | Expand


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 ... report.pdf

https://github.com/EduardoSP6/Fast_Repo ... WH.prg.~2~

Regards, saludos.