Solved

crystal report send email with excel attachment

Posted on 2007-12-04
1
1,098 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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 …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 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