Send Telerik Report as email attachment

Thread is closed for posting
9 posts, 0 answers
  1. David Silveria
    David Silveria avatar
    234 posts
    Member since:
    May 2006

    Posted 04 Jul 2008 Link to this post

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

    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);
               //smtp host is the name or IP of the host computer used for sending the email
               string smtpHost = "";
               SmtpClient client = new SmtpClient(smtpHost);

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

  2. Ismail
    Ismail avatar
    17 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
    Steve avatar
    10940 posts

    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,
    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
    19 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
  6. Adil
    Adil avatar
    26 posts
    Member since:
    Mar 2014

    Posted 09 Feb 2016 in reply to Hadib Ahmabi Link to this post

    I checked the all the posts but i cant find actual solution ??

     Also i read this blog too but it explains very very plain and i download that project that one is now working and its for web form i'm using MVC 

     I think its impossible to send report as attachment in mail

    here i found some thing 

    I'm sending parameters from ajax

         var ident = $('#identCE').val();
        var viewer = $("#reportViewer2").data('telerik_ReportViewer');
        var postData = {
            report1: viewer.reportSource($.extend({}, viewer.reportSource(), { report: "CustomerEnrollment.trdx", parameters: { 'CustomerId': ident } }))
        var url = '../AccountMaint/MailReport';
            url: url,
            type: "POST",
            dataType: 'json',
            data: postData,
            success: function (data) {



    and then catch on MVC controller


            public void MailReport(Telerik.Reporting.Report report1)

                string mimeType;
                string extension;
                Encoding encoding;

                byte[] reportBytes =
                ReportProcessor.Render("PDF", report1, null, out mimeType, out extension, out encoding);

                MemoryStream ms = new MemoryStream(reportBytes);
                ms.Position = 0;

                Attachment attachment = new Attachment(ms, report1.Name + "." + extension);
                MailMessage msg = new MailMessage("", "", "Test Report", "Report Is Attached");
                SmtpClient client = new SmtpClient();



    but report1 is object but its not getting report so in mail attachment report is empty!!!


    Help me please


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

    Posted 09 Feb 2016 in reply to Adil Link to this post

    This scenario occurs when the Database connection not established. 
  8. Stef
    Stef avatar
    3610 posts

    Posted 09 Feb 2016 Link to this post

    Hi Adil,

    An HTMl5 Viewer's reportSource does not contain instance of a report or InstanceReportSource that can b used by your method. For more details, please check Report Sources.
    You will have to create an instance of the report in code based on the string description of the report received through the viewer's reportSource.

    Please use the support ticketing system or public forums to post any further technical questions.
    Thank you for your understanding.

    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 Feedback Portal and vote to affect the priority of the items
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.