?
Solved

crystal report send email with excel attachment

Posted on 2007-12-04
1
Medium Priority
?
1,106 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

800 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