This
code snippet describes how to send Crystal Reports via Email Programmatically
using
System;
using
System.Net;
using
System.Net.Mail;
using
System.Windows.Forms;
using
CrystalDecisions.CrystalReports.Engine;
using
CrystalDecisions.Shared;
namespace
CSharpDeveloper.Core
{
public class CrystalReportHelperClass
{
public void
SendEmail(string emailId, string subject, string
body, ReportDocument rpt, string fileName)
{
try
{
MailMessage mm = new
MailMessage();
mm.From = new MailAddress("xyz@example.com", "From Name");
mm.To.Add(new MailAddress(emailId, "To Name"));
mm.Subject = subject;
mm.Body = body;
mm.Attachments.Add(
new
Attachment(rpt.ExportToStream(ExportFormatType.PortableDocFormat), fileName)
);
SmtpClient sc = new
SmtpClient("smtp.example.com");
sc.Credentials = new NetworkCredential("xyz@example.com", "********");
sc.Send(mm);
MessageBox.Show("Email
successfully sent to " + emailId);
}
catch (Exception
e)
{
if (
MessageBox.Show("Unable
to send email to "
+
emailId + " due to following error:\n\n"
+ e.Message, "Email send error"
,
MessageBoxButtons.RetryCancel, MessageBoxIcon.Error)
== DialogResult.Retry
)
{
this.SendEmail(emailId, subject, body, rpt,
fileName);
}
}
}
}
}
check this link
ReplyDeletehttp://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-export-pdf.htm
crystal reports export..