Solved

crystal report send email with excel attachment

Posted on 2007-12-04
1
1,104 Views
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.CreateMicrosoftMailDestinationOptions();
            ExportOptions exportOpts = new ExportOptions();
 
 
            mailOpts.MailCCList = "";
            mailOpts.MailMessage = "This is a test";
            mailOpts.MailSubject = "This is a test";
            mailOpts.MailToList = "mweaver@k-and-s.com";
            mailOpts.Password = "12345";
            mailOpts.UserName = "mweaver";
 
            exportOpts.ExportFormatOptions = xlOpts;
            exportOpts.ExportDestinationOptions = mailOpts;
            exportOpts.ExportDestinationType = ExportDestinationType.MicrosoftMail;
            exportOpts.ExportFormatType = ExportFormatType.Excel;
            reportDocument1.Export(exportOpts);

Open in new window

0
Comment
Question by:KS_Mis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
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
Try
  GenRep()
  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)
  objMsg.To.Add(txtTo.Text)
  If txtCC.Text <> "" Then
     objMsg.CC.Add(txtCC.Text)
   End If
   objMsg.Subject = txtSub.Text
   If txtMsg.Text <> "" Then
      objMsg.Body = txtMsg.Text
   Else
      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.Send(objMsg)
   objMsg.Dispose()
   objSmtp = Nothing
   Kill(Server.MapPath(xFileName))
   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

0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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