cancel
Showing results for 
Search instead for 
Did you mean: 

export crystal report to pdf then send to email using outlook

Former Member
0 Kudos

good day sir,

this is my whole code for creating a crystal report and exporting it to a pdf file:

Public Sub rsvrpt()

        Dim rpt As New reservationrpt() 'The report you created.

        Dim MyCommand As New SqlCommand()

        Dim myDA As New SqlDataAdapter()

        Dim myDS As New DataSet2() 'The DataSet you created.

        Dim cn As New SqlConnection(ConnectString())

        Try

            MyCommand.Connection = cn

            MyCommand.CommandText = "SELECT * FROM maintable where irsno=" + irsn + " And branchID='" + branch + "'"

            MyCommand.CommandType = CommandType.Text

            myDA.SelectCommand = MyCommand

            myDA.Fill(myDS, "maintable")

            'myDA.SelectCommand.CommandText = "Select fullname from usertbl where username='" + Login.txtuser.Text + "'"

            'myDA.Fill(myDS, "usertbl")

            myDA.SelectCommand.CommandText = "Select * from roomtbl where irsno=" + irsn + " And branchID='" + branch + "'"

            myDA.Fill(myDS, "roomtbl")

            myDS.EnforceConstraints = False

            rpt.SetDataSource(myDS)

            CrystalReportViewer1.ReportSource = rpt

            'rpt.PrintOptions.PrinterName = "EPSON LX-300+ /II"

            'rpt.PrintToPrinter(1, False, 0, 0)

        Catch Excep As Exception

            MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK,

            MessageBoxIcon.Error)

        End Try

      

        Try

            Dim CrExportOptions As ExportOptions

            Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()

            Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()

            CrDiskFileDestinationOptions.DiskFileName = "C:\Users\Frontliner0102\Desktop\reservation.pdf"

            CrExportOptions = rpt.ExportOptions

            With CrExportOptions

                .ExportDestinationType = ExportDestinationType.DiskFile

                .ExportFormatType = ExportFormatType.PortableDocFormat

                .DestinationOptions = CrDiskFileDestinationOptions

                .FormatOptions = CrFormatTypeOptions

            End With

            rpt.Export()

        Catch ex As Exception

        End Try

    End Sub

i want to send the crystal report to an email using microsoft outlook but i dont have any idea how to start it.can anyone give me some advice or guide on how to dot it? I searched throughout the internet but all i have read is that using SMPT server.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hello,

You can do it this way:

exportOpts.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.MicrosoftMail;

exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;

mailOpts.MailToList = "Don Williams";

mailOpts.MailSubject = "Attached is a PDF file - .net Export test ";

mailOpts.MailSubject = "This is the Subject";

//MailOpts.MailCCList = "John Doe";

mailOpts.UserName = "NetworkUserName";

mailOpts.Password = "pw";

exportOpts.ExportDestinationOptions = mailOpts;

rpt.Export(exportOpts);

MessageBox.Show("Mail sent Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

Requires MAPI or the MS Client to be installed.

If Outlook is not available then we need to know what version of CR runtime you are using?

If it's not available then export to Disk and then use Outlook API's to send an e-mail as an attachment.

Don

Former Member
0 Kudos

Good Day sir, this is my code so far:

Dim fname As String = "C:\Users\Frontliner0102\Desktop\reservation.pdf"

        Dim OutlookMessage As outlook.MailItem

        Dim AppOutlook As outlook.Application

        Try

            OutlookMessage = AppOutlook.CreateItem(outlook.OlItemType.olMailItem)

            Dim Recipents As outlook.Recipients = OutlookMessage.Recipients

            Recipents.Add("chestercc@izones.com.ph")

            OutlookMessage.To = txtEmail.Text

            OutlookMessage.Subject = "Sending through Outlook"

            OutlookMessage.Body = "Testing outlook Mail"

            OutlookMessage.BodyFormat = outlook.OlBodyFormat.olFormatHTML

            Dim oAttach As outlook.Attachment

            oAttach = OutlookMessage.Add(fname)

            OutlookMessage.Send()

        Catch ex As Exception

            'MessageBox.Show("Mail could not be sent") 'if you dont want this message, simply delete this line

        Finally

            OutlookMessage = Nothing

            AppOutlook = Nothing

        End Try

my code does.not send an attachment email to the given email address. i am using vs.net2010 and crystal report version 13

0 Kudos

Hi Chester,

OK so all you are doing is trying to attach a PDF to an e-mail using Windows Outlook API's. Search here, there is a kbase with sample code on how to.

If you want to set the destination to Outlook using CR Export type then use my code.

Don

Former Member
0 Kudos

Good Day sir, thank you for answering my question.For now,i'm using my Gmail account to send an attached email and it works.i will try to find solution here regarding for using microsoft outlook for sending a message.You're great! ^^

0 Kudos

Great...

Make sure you ahve Outlook running. I kind of recall that if it's not it won't work, CR assumes the client is running.

Don

Answers (0)