Send Telerik Report as email attachment

6 posts, 0 answers
  1. David Silveria
    David Silveria avatar
    234 posts
    Member since:
    May 2006

    Posted 04 Jul 2008 Link to this post

    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.

  2. Ismail
    Ismail avatar
    14 posts
    Member since:
    Oct 2012

    Posted 17 Jul 2012 Link to this post

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

  3. Justin
    Justin avatar
    9 posts
    Member since:
    May 2012

    Posted 02 Oct 2012 Link to this post

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

  4. Steve
    Admin
    Steve avatar
    10942 posts
    Member since:
    May 2014

    Posted 03 Oct 2012 Link to this post

    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.

  5. Senthil
    Senthil avatar
    7 posts
    Member since:
    Aug 2012

    Posted 09 May 2013 Link to this post

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

Back to Top