Send Telerik Report as email attachment

Thread is closed for posting
9 posts, 0 answers
  1. 2A48F178-3353-4D98-8DB0-E876C7634A5B
    2A48F178-3353-4D98-8DB0-E876C7634A5B 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. AF65E3B0-F0C9-4074-B40B-DD3561F58196
    AF65E3B0-F0C9-4074-B40B-DD3561F58196 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. 9C9E2EFF-F054-4D26-8863-F4EF637B13FC
    9C9E2EFF-F054-4D26-8863-F4EF637B13FC 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. 3BD6F94B-4C03-46D3-8568-9982F1F201BF
    3BD6F94B-4C03-46D3-8568-9982F1F201BF avatar
    10940 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,
    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. 0B1D40D4-3A1E-45E1-BDFC-EA856E726AFA
    0B1D40D4-3A1E-45E1-BDFC-EA856E726AFA 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. EFF1CD34-F301-4F99-AD34-86033F9FD8D7
    EFF1CD34-F301-4F99-AD34-86033F9FD8D7 avatar
    181 posts
    Member since:
    Nov 2011
  7. B1E8D9A3-B353-44D1-8E6D-E9D1998FA05A
    B1E8D9A3-B353-44D1-8E6D-E9D1998FA05A avatar
    26 posts
    Member since:
    Mar 2014

    Posted 09 Feb 2016 in reply to EFF1CD34-F301-4F99-AD34-86033F9FD8D7 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


  8. 0B1D40D4-3A1E-45E1-BDFC-EA856E726AFA
    0B1D40D4-3A1E-45E1-BDFC-EA856E726AFA avatar
    19 posts
    Member since:
    Aug 2012

    Posted 09 Feb 2016 in reply to B1E8D9A3-B353-44D1-8E6D-E9D1998FA05A Link to this post

    This scenario occurs when the Database connection not established. 
  9. 3D78FABF-3604-4921-AD8D-930AB537F0F8
    3D78FABF-3604-4921-AD8D-930AB537F0F8 avatar
    3610 posts
    Member since:
    Jul 2017

    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.