Skip Navigation LinksHome / Community & Support / Code Library / Telerik Reporting > General and Integration Projects > Send Telerik Report as email attachment

Not answered Send Telerik Report as email attachment

Feed from this thread
  • David Silveria Master avatar

    Posted on Jul 4, 2008 (permalink)

    Requirements
    Telerik Reporting version
     Q2 2009 SP1+
    .NET version  2.0 +
    Visual Studio version  VS2005+
    programming language  C#
    To convert code Telerik online converter

    PROJECT DESCRIPTION
    The Report Viewers (Win and Web) do not support sending of reports via e-mail out-of-the-box. To mail a report you have to first render the report into a convenient format and then attach it to a mail message. Here is a possible way of how to achieve this by using the SmtpClient object:

    void MailReport(Telerik.Reporting.Report report, string from, string to, string subject, string body)
           {
               ReportProcessor reportProcessor = new ReportProcessor();
               RenderingResult result = reportProcessor.RenderReport("PDF", report, null);
     
               MemoryStream ms = new MemoryStream(result.DocumentBytes);
               ms.Position = 0;
     
               Attachment attachment = new Attachment(ms, report.Name + ".pdf");
               MailMessage msg = new MailMessage(from, to, subject, body);
               msg.Attachments.Add(attachment);
               //smtp host is the name or IP of the host computer used for sending the email
               string smtpHost = "255.255.255.0";
               SmtpClient client = new SmtpClient(smtpHost);
               client.Send(msg);
           }

    You can find attached a sample project that shows the above code in action.

    Attached files

    Reply

  • Ismail avatar

    Posted on Jul 17, 2012 (permalink)

    how can i get the reoprt to pass parameters when it is being sent as an attachment?

    Reply

  • Justin avatar

    Posted on Oct 2, 2012 (permalink)

    I have the same question. I can't use a reportviewer to initiate the email.

    Reply

  • Steve Steve avatar

    Posted on Oct 3, 2012 (permalink)

    Hello guys,

    Things have changed in the Q2 2012 version of Telerik Reporting, so please check the respective help article for Exporting Reports Programmatically. Using the snippet in the article the way to provide parameters to the report is the following:

    Telerik.Reporting.Processing.ReportProcessor reportProcessor =
        new Telerik.Reporting.Processing.ReportProcessor();
     
    // set any deviceInfo settings if necessary
    System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
     
    Telerik.Reporting.InstanceReportSource instanceReportSource =
        new Telerik.Reporting.InstanceReportSource();
     
    instanceReportSource.ReportDocument = report1;
     
    // "OrderNumber" is the name of the parameter and "SO43659" is the default value
    instanceReportSource.Parameters.Add(new Telerik.Reporting.Parameter("OrderNumber", "SO43659"));
     
    Telerik.Reporting.Processing.RenderingResult result =
        reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
     
    // The rest of the snippet goes here

    @Justin - scheduling and email sending cannot be initiated from the viewer. Please review carefully this post which elaborates on the available solution.

    All the best,
    Steve
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

    Reply

  • Senthil avatar

    Posted on May 9, 2013 (permalink)

    its possible in web application to view the outlook and attach the pdf file

    Reply

  • Hadib Ahmabi Intermediate avatar

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Code Library / Telerik Reporting > General and Integration Projects > Send Telerik Report as email attachment