Email report from Crystal Reports using VB.NET

This handy bit of code, taken from the Business Objects Knowledgebase shows how to export your report from Crystal Reports to PDF and then email them using VB.NET using Microsoft Mail. This means however, that you need an email client on the user's machine. The CS/C++ versions are available on the site as well.

Public Sub ExportToMSMail(ByVal toList As String, ByVal subject As String, ByVal message As String, _ ByVal ccList As String, ByVal user As String, ByVal password As String) ' Declare variables and retrieve the export options. Dim pdfOpts As PdfRtfWordFormatOptions = _ ExportOptions.CreatePdfRtfWordFormatOptions() Dim mailOpts As MicrosoftMailDestinationOptions = _ ExportOptions.CreateMicrosoftMailDestinationOptions() Dim exportOpts As ExportOptions = New ExportOptions ' Set the PDF format options. pdfOpts.UsePageRange = False exportOpts.ExportFormatOptions = pdfOpts ' Set the mail options. mailOpts.MailCCList = ccList mailOpts.MailMessage = message mailOpts.MailSubject = subject mailOpts.MailToList = toList mailOpts.Password = password mailOpts.UserName = user exportOpts.ExportDestinationOptions = mailOpts ' Export the report. exportOpts.ExportDestinationType = _ ExportDestinationType.MicrosoftMail exportOpts.ExportFormatType = _ ExportFormatType.PortableDocFormat Report.Export(exportOpts) End Sub

Leave a Comment

Your Comment