using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using Telerik.Reporting;
using Telerik.Reporting.Processing;

namespace HTML5MailButton.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public EmptyResult EmailReport(string test)
        {


            ReportProcessor reportProcessor = new ReportProcessor();
            var URS = new UriReportSource { Uri = Server.MapPath("~") + test };
            RenderingResult result = reportProcessor.RenderReport("PDF", URS, null);

            MemoryStream ms = new MemoryStream(result.DocumentBytes);
            ms.Position = 0;

            //replace the settings with valid for your application
            Attachment attachment = new Attachment(ms, "myreport" + ".pdf");
            string from = "", to = "", subject = "", body = "";
            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);

            return new EmptyResult();

        }
    }
}