Hello,

i m using vb.net with MS Access database & oledbconnection in my project.

now i want to mail my crystal report in pdf format to respected email-id,
how can i do this?????

i spent lot of time for searching some helpful bt didn't get

Dani AI

Generated

A concise, practical pattern that complements 's scenario and 's suggestion is to export the Crystal Report straight into a MemoryStream and attach that stream to System.Net.Mail.MailMessage. This avoids creating temp files on the web server (permission and cleanup headaches) and sends the PDF directly to a specific address.

Using rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
    rpt.Load(Server.MapPath("~/Reports/MyReport.rpt"))
    ' set report parameters or call rpt.SetDataSource(...) before export

    Dim pdfStream As System.IO.Stream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
    pdfStream.Position = 0

    Using msg As New System.Net.Mail.MailMessage()
        msg.From = New System.Net.Mail.MailAddress("sender@domain.com")
        msg.To.Add("recipient@domain.com")
        msg.Subject = "Report PDF"
        msg.Body = "Attached is the requested report."
        msg.Attachments.Add(New System.Net.Mail.Attachment(pdfStream, "MyReport.pdf", "application/pdf"))

        Using smtp As New System.Net.Mail.SmtpClient("smtp.server.com", 587)
            smtp.EnableSsl = True
            smtp.Credentials = New System.Net.NetworkCredential("smtpuser", "smtppass")
            smtp.Send(msg)
        End Using
    End Using

    rpt.Close()
    rpt.Dispose()
End Using

Notes and common gotchas: set all report parameters and the data source before calling ExportToStream; always close/dispose ReportDocument to avoid memory leaks; large reports load fully into memory — for very large PDFs consider a disk-based approach; ensure the server has the correct Crystal runtime and that the app pool bitness matches (32/64-bit); verify SMTP host/port/SSL and credentials and that the sending address is permitted by the mail relay. This pattern satisfies the original goal of sending the generated PDF directly to a target email without leaving temporary files behind.

Recommended Answers

All 6 Replies

Hi,

To export a Crystal Report to PDF.
You can find some information,

To send an Email, try this:

Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "you@yourcompany.com"
mail.Subject = "this is a test email."
mail.Body = "this is my test email body."
Dim attachment As New MailAttachment(Server.MapPath("test.pdf")) 'create the attachment
mail.Attachments.Add(attachment) 'add the attachment
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)

Hi,

To export a Crystal report to PDF, look here.

thank you sir,
one more question
is it possible to directly send the generated pdf file to specific email id?????

if possible this will be large milestone for me....

Thnx in advance

Hi,

I think yoou can only send the generated file as attachment, but you can always write code that you can't change the specific Email ID.
See previous post how to send an Email.

Thank U Sir.

Hi,

No problem :)
Mark this thread as resolved and rating is a way of saying thank you. Don't forget to rate always, thanks. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.