Solved

crystal report send email with excel attachment

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 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