Email a pdf file

Can anyone help me to write some coding to send a pdf file via email using FastReports email functionality.
I can do it manually and all goes fine, I can send a saved file using VB (which would work) but is not the point of FastReports.

I need to do it in VB (I am using Visual Studio 2008). Here is my starting effort but where from here as can't sem to finda way of adding SMTP server details or attachments
Dim ListReport = New FastReport.Report
        ListReport.Load(My.Settings.ReportLocation & "ReportInvoiceNoDiscount.frx")
        ListReport.SetParameterValue("NMDbConnectionString", "Data Source=" & My.Settings.Server & "\SQLEXPRESS;AttachDbFilename=;Initial Catalog=NMDb;Integrated Security=True;Persist Security Info=False;User ID=;Password=")
        ListReport.SetParameterValue("ShopperID", lblShopperIDV.Text)
        ListReport.EmailSettings.Subject = "Test"

Any help much appreciated

Gus

Comments

  • edited 3:35PM
    Hello,

    Here is C# equivalent that exports the report to pdf and sends it via SMTP:
    Report report = new Report();
    report.Load(...);
    report.RegisterData(...);
    report.Prepare();
    
    PDFExport pdfExport = new PDFExport();
    EmailExport export = new EmailExport();
    
    // set up Account properties...
    export.Account.Host = "...";
    export.Account.Address = "...";
    
    // set up email properties...
    export.Address = "...";
    export.Subject = "...";
    export.MessageBody = "...";
    
    // send email
    export.Export = pdfExport;
    export.SendEmail(report);
    
  • edited 3:35PM
    Thanks for the sample code. I am no C programmer but should be able to use this as a basis for working it out in VB. I'll give it a try and report back.

    Cheers

    Gus >
  • edited 3:35PM
    Thanks for you assistance
    I have enclosed my VB Code below for anyone that is interested. It is used to send an email to a customer with Invoice attached
    ' Prepare Report
            Dim ListReport = New FastReport.Report
            ListReport.Load(My.Settings.ReportLocation & "Invoice.frx")
            ListReport.SetParameterValue("NMDbConnectionString", "Data Source=" & My.Settings.Server & "\SQLEXPRESS;AttachDbFilename=;Initial Catalog=NMDb;Integrated Security=True;Persist Security Info=False;User ID=;Password=")
            ListReport.SetParameterValue("ShopperID", lblShopperIDV.Text)
            ListReport.Prepare()
    
            ' Create Export File
            Dim PDFExport As FastReport.Export.Pdf.PDFExport = New FastReport.Export.Pdf.PDFExport
            ListReport.Export(PDFExport, My.Settings.EMailLocation & "EMailReport" & lblOrderNo.Text & ".pdf")
    
            ' Account Properties
            Dim EMailExport As FastReport.Export.Email.EmailExport = New FastReport.Export.Email.EmailExport
            EMailExport.Account.Host = "xxx" ' SMTP Host
            EMailExport.Account.Address = "xxx" ' From EMail Address
            EMailExport.Account.UserName = "xxx" ' SMTP ID
            EMailExport.Account.Password = "xxx" ' SMTP Password
            EMailExport.Account.Port = 25
            EMailExport.Account.EnableSSL = False
    
            ' EMail Properties
            EMailExport.Address = "recipient@abc.co.uk"
            EMailExport.Subject = "Test"
            EMailExport.MessageBody = "Body of EMail"
    
            ' Send Mail
            EMailExport.Export = PDFExport
            EMailExport.SendEmail(ListReport)
            MsgBox("Email Sent Successfully", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Action Confirmed")
    


    Now one last question:
    Is there a way to either amend the name of the pdf file being attached or is it possible to actually attach the exported file

    Cheers

    Gus
  • edited 3:35PM
    FastReport uses report.FileName property to form an attachment name. If it is empty, the attachment will have "Report" name.
  • edited 3:35PM
    Thanks for that - Works a treat.
  • edited January 2014
    Hello,
    i tried this VB code and it working... but i have an issue... a small problem...
    I use am image as background as watermark... and the image is not being exported to pdf and to email...
    Can anyone help me ?!?!

    here is my code :
            ' Prepare Report
            Dim ListReport = New FastReport.Report
    
            Dim Factura As String = My.Settings.Reports.ToString & "\Ordens_Prod_Auto.frx"
            strSQL = "SELECT * FROM VW_CABEC_DOCS  WHERE Codigo LIKE ('" & DOCUMENTO_CBDataGridView.Rows(Nrow).Cells("CodDoc").Value.ToString & "')"
            Dim strSQL2 = "SELECT * FROM VIEW_LINHAS_DOCS WHERE Codigo = (SELECT Codigo_Auto FROM VW_CABEC_DOCS WHERE Codigo LIKE ('" & DOCUMENTO_CBDataGridView.Rows(Nrow).Cells("CodDoc").Value.ToString & "')) ORDER BY LINHA"
            strPerfil = "SELECT SUM(Quantidade) AS Quantidade FROM dbo.VW_Perfil_1 WHERE (CodLinhaDocumento IN (SELECT Codigo_Auto FROM dbo.DOCUMENTO_LN WHERE (Codigo = (SELECT Codigo_Auto FROM dbo.DOCUMENTO_CB WHERE (Codigo = '" & DOCUMENTO_CBDataGridView.Rows(Nrow).Cells("CodDoc").Value.ToString & "')))))"
            Try
                ListReport.load(Factura)
                ListReport.Dictionary.Connections(0).ConnectionString = My.Settings.InovaConnectionString
            Catch
                DevComponents.DotNetBar.MessageBoxEx.Show("Report file not found!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Exit Sub
            End Try
            Dim TD As FastReport.Data.TableDataSource = ListReport.GetDataSource("DOCUMENTO_CB")
            TD.SelectCommand = strSQL
            Dim LD As FastReport.Data.TableDataSource = ListReport.GetDataSource("DOCUMENTO_LN")
            LD.SelectCommand = strSQL2
            Dim Prfd As FastReport.Data.TableDataSource = ListReport.GetDataSource("Perfil")
            Prfd.SelectCommand = strPerfil
            Dim s2Via As FastReport.TextObject = ListReport.FindObject("s2Via")
            s2Via.Text = " "
    
            Dim W As New FastReport.Watermark
            W.Image = My.Resources.Folha1
            W.ImageSize = FastReport.WatermarkImageSize.Stretch
            CType(ListReport.Pages.Item(0), FastReport.ReportPage).Watermark = W
            
            ' Create Export File
            Dim PDFExport As FastReport.Export.Pdf.PDFExport = New FastReport.Export.Pdf.PDFExport
            PDFExport.Background = True
            PDFExport.EmbeddingFonts = True
            PDFExport.Compressed = True
            PDFExport.PrintOptimized = True
    
            ListReport.prepare()
    
            ListReport.Export(PDFExport, "Document" & ".pdf")
    
            ' Account Properties
            Dim EMailExport As FastReport.Export.Email.EmailExport = New FastReport.Export.Email.EmailExport
            EMailExport.Account.Host = "xxx" ' SMTP Host
            EMailExport.Account.Address = "xxx" ' From EMail Address
            EMailExport.Account.UserName = "xxx" ' SMTP ID
            EMailExport.Account.Password = "xxx" ' SMTP Password
            EMailExport.Account.Port = 25
            EMailExport.Account.EnableSSL = False
    
            ' EMail Properties
            EMailExport.Address = "xxx"
            EMailExport.Subject = "Ordem de Produ?§??o " & DOCUMENTO_CBDataGridView.Rows(Nrow).Cells("CodDoc").Value.ToString
            EMailExport.MessageBody = "Aqui vai o documento que pediste!"
    
            ' Send Mail
            EMailExport.Export = PDFExport
            EMailExport.SendEmail(ListReport)
            DevComponents.DotNetBar.MessageBoxEx.Show("Document Sent!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information)
    

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.