Solved

crystal report send email with excel attachment

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Achieve json result 2 65
XML & .net 5 41
Visual Studio - "Windows Form Designer generated code" 2 39
.NET tools for adding thread safety to a web app? 3 17
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now