Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

crystal report send email with excel attachment

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

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 …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

604 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