MHTML export in e-mail body

6 posts, 0 answers
  1. Marcelo Torres Assis
    Marcelo Torres Assis avatar
    4 posts
    Member since:
    May 2010

    Posted 03 Feb 2011 Link to this post

    I am exporting a report to MHTML in order to insert it in a email. Although the export is working, I could not find a way to include it in the email body using the MailMessage class of the framework . net. Could anyone help me in this issue?
  2. Duncan
    Duncan avatar
    4 posts
    Member since:
    Feb 2009

    Posted 12 Apr 2011 Link to this post

    I would also like to know how to do this. I cannot seem to work out a way to achieve it.
  3. DevCraft banner
  4. Arun Kumar
    Arun Kumar avatar
    60 posts
    Member since:
    Nov 2009

    Posted 18 May 2011 Link to this post

    Any Solution? I am also need this.
  5. Massimiliano Bassili
    Massimiliano Bassili avatar
    323 posts
    Member since:
    May 2006

    Posted 18 May 2011 Link to this post

    Guys, you're looking at the wrong place as this is not part of the software and you should take care of it manually. There are multiple articles on the matter e.g. http://www.google.com/search?q=.net+include+file+in+email+body

    Cheers!
  6. Duncan
    Duncan avatar
    4 posts
    Member since:
    Feb 2009

    Posted 31 Aug 2011 Link to this post

    Thanks for your response, however I dont feel you are understanding the issue.

    The MHTML export contains the images embedded in the html somehow, and it is this which is causing the issue.

    There is no problem with producing a HTML email body, but rather having the MHTML embedded images in the email body.

    Thanks
  7. Chavdar
    Admin
    Chavdar avatar
    898 posts

    Posted 06 Sep 2011 Link to this post

    Hi Duncan,

    Currently it is not possible to send a MHTML document generated by Telerik Reporting directly in the message body of an e-mail. Still you may take a look at the Sending Inline MHTML thread at StackOverflow for alternative solutions. One of the possible ways is to save the html pages and images as separate files and then add the images as LinkedResources to the html body of the message.

    Here is a sample code snippet which illustrates how to export a report to HTML format and save its streams as files:
    class HtmlToFileRenderer
    {
        const string BasePath = "C:\\Temp\\HtmlDocument";
        List<FileStream> files = new List<FileStream>();
     
        Stream CreateStream(string name, string extension, Encoding encoding, string mimeType)
        {
            var filePath = Path.ChangeExtension(Path.Combine(BasePath, name), extension);
            var fileStream = new FileStream(filePath, FileMode.Create);
            this.files.Add(fileStream);
            return fileStream;
        }
     
        public void Render(IReportDocument report)
        {
            var deviceInfo = new Hashtable();
            deviceInfo["BasePath"] = BasePath;
            var documentName = "";
            var reportProcessor = new ReportProcessor();
            reportProcessor.RenderReport("HTML", new ReportCatalog(), deviceInfo, this.CreateStream, out documentName);
            foreach (var fileStream in this.files)
            {
                fileStream.Dispose();
            }
            this.files.Clear();
        }
    }
     
    void button1_Click(object sender, EventArgs e)
    {
        var fileRenderer = new HtmlToFileRenderer();
        fileRenderer.Render(new ReportCatalog());
    }

    Hope this helps.

    Greetings,
    Chavdar
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top
DevCraft banner