I want to send crystal report as email

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Web.Mail

Public Class Form1
    Dim cryRpt As New ReportDocument
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim cryRpt As New ReportDocument
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        cryRpt.Load("K:\WindowsApplication3\cryRpt1.rpt")
        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.Refresh()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Dim CrExportOptions As ExportOptions
            Dim CrDiskFileDestinationOptions As New  _
            DiskFileDestinationOptions()
            Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
            CrDiskFileDestinationOptions.DiskFileName = _
                                        "k:\crystalExport.pdf"
            CrExportOptions = cryRpt.ExportOptions
            With CrExportOptions
                .ExportDestinationType = ExportDestinationType.DiskFile
                .ExportFormatType = ExportFormatType.PortableDocFormat
                .DestinationOptions = CrDiskFileDestinationOptions
                .FormatOptions = CrFormatTypeOptions
            End With
            cryRpt.Export()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

        sendMail()

    End Sub

    Private Sub sendMail()
        Dim Msg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage()
        Try
            Dim Smtp As SmtpMail
            SmtpMail.SmtpServer.Insert(0, "www.google.com")
            Dim Msg As MailMessage = New MailMessage
            Msg.To = "anne_shehara@yahoo.com"
            Msg.From = "anneshehara@gmail.com"
            Msg.Subject = "Crystal Report Attachment "
            Msg.Body = "Crystal Report Attachment "
            Msg.Attachments.Add(New MailAttachment("k:\crystalExport.pdf"))

            Smtp.Send(Msg)   
            MsgBox("the msg has been sent")
        Catch ex As Exception
            MsgBox(ex.ToString)

        End Try

    End Sub

button2 functionas are not working
i got the error like this:"The "SendUsing" configuration value is invalid."

Dani AI

Generated

Quick summary for : the runtime error "The 'SendUsing' configuration value is invalid" normally means the CDO/System.Web.Mail code is trying to use the server pickup method or an unset/invalid SMTP host rather than a real SMTP endpoint. System.Web.Mail (SmtpMail) is deprecated; migrate to System.Net.Mail.SmtpClient which supports credentials and TLS. (learn.microsoft.com)

A compact, practical approach: export the report to a stream (no temporary file lock), attach that stream to a MailMessage, and send with SmtpClient configured for your SMTP server (Gmail requires TLS/port 587 or SSL/465 and generally an App Password or OAuth). After export, close and dispose the ReportDocument to free temp files. (learn.microsoft.com)

Example (VB.NET, replace credentials and addresses):

' Export report to a stream and send via SmtpClient
Dim pdfStream As System.IO.Stream = cryRpt.ExportToStream(ExportFormatType.PortableDocFormat)
pdfStream.Position = 0

Using mail As New System.Net.Mail.MailMessage()
  mail.From = New System.Net.Mail.MailAddress("you@gmail.com")
  mail.To.Add("recipient@example.com")
  mail.Subject = "Report"
  mail.Attachments.Add(New System.Net.Mail.Attachment(pdfStream, "report.pdf", "application/pdf"))

  Using smtp As New System.Net.Mail.SmtpClient("smtp.gmail.com", 587)
    smtp.EnableSsl = True
    smtp.Credentials = New System.Net.NetworkCredential("you@gmail.com", "your-app-password")
    smtp.Send(mail)
  End Using
End Using

cryRpt.Close()
cryRpt.Dispose()

Quick troubleshooting checklist: don’t use "www.google.com" as SMTP host; check for duplicate local variable declarations (your send routine redeclares Msg); ensure the account allows SMTP (App Password or OAuth for Gmail); check firewall/ISP blocking of outbound SMTP ports; inspect SmtpException.InnerException for details. s MSDN pointer is a useful reference for examples.

Here is an article on MSDN that has code to do exactly what you are wanting.

Hope this helps

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.