crystal report send email with excel attachment

Posted on 2007-12-04
Last Modified: 2013-12-16
I would like to send an e-mail out from a crystal report with the report exported to excel as an attachment.  I have the attached code.  I am getting the error
Type Initialization  Exception in CyrstalDecisions.CrystalReports.Engine.dll - Type Initializer for CyrstalDecisions.CrystalReports.Engine.MapiMessage threw an exception.
ExcelFormatOptions xlOpts = new ExcelFormatOptions();

            MicrosoftMailDestinationOptions mailOpts =


            ExportOptions exportOpts = new ExportOptions();

            mailOpts.MailCCList = "";

            mailOpts.MailMessage = "This is a test";

            mailOpts.MailSubject = "This is a test";

            mailOpts.MailToList = "";

            mailOpts.Password = "12345";

            mailOpts.UserName = "mweaver";

            exportOpts.ExportFormatOptions = xlOpts;

            exportOpts.ExportDestinationOptions = mailOpts;

            exportOpts.ExportDestinationType = ExportDestinationType.MicrosoftMail;

            exportOpts.ExportFormatType = ExportFormatType.Excel;


Open in new window

Question by:KS_Mis
1 Comment

Accepted Solution

stcindia earned 500 total points
ID: 20417457
May be not exactly solution to your problem,
With one of my ASP.NET (VB) I am using
Export and save the file on disk and then send the mail through SMTPclient
Attached is attached as is from my live project, hoping this may help
Dim SMTPUser As String = ConfigurationManager.AppSettings("SMTPUser")

Dim SMTPPass As String = ConfigurationManager.AppSettings("SMTPPass")

Dim SMTPEmail As String = ConfigurationManager.AppSettings("SMTPEmail")

Dim SMTPFrom As String = ConfigurationManager.AppSettings("SMTPFrom")

Dim SMTPServer As String = ConfigurationManager.AppSettings("SMTPServer")

Dim objMsg As New MailMessage

Dim objSmtp As New SmtpClient

Dim objSmtpUser As New Net.NetworkCredential(SMTPUser, SMTPPass)

Dim mf As New MyFunction

Dim xFileName As String



  crReport.ExportToDisk(ExportFormatType.PortableDocFormat, Server.MapPath("mail.pdf"))

  xFileName = Left(RepName, InStr(RepName, ".")) & "pdf"

  System.IO.File.Copy(Server.MapPath("mail.pdf"), Server.MapPath(xFileName), True)


  If txtCC.Text <> "" Then


   End If

   objMsg.Subject = txtSub.Text

   If txtMsg.Text <> "" Then

      objMsg.Body = txtMsg.Text


      objMsg.Body = " "

   End If

   objMsg.Attachments.Add(New Attachment(Server.MapPath(xFileName)))

   objMsg.From = New MailAddress(SMTPEmail, SMTPFrom)

   objSmtp.Host = SMTPServer

   objSmtp.Credentials = objSmtpUser



   objSmtp = Nothing


   ClientScript.RegisterStartupScript(Me.GetType, "", mf.GetMsgBoxScript("Message Sent"))

Catch ex As Exception

   ClientScript.RegisterStartupScript(Me.GetType, "", mf.GetMsgBoxScript(ex.Message))

End Try

Open in new window


Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now