This is a migrated thread and some comments may be shown as answers.

MHTML export in e-mail body

5 Answers 190 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Marcelo Torres Assis
Top achievements
Rank 1
Marcelo Torres Assis asked on 03 Feb 2011, 01:09 PM
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?

5 Answers, 1 is accepted

Sort by
0
Duncan
Top achievements
Rank 1
answered on 13 Apr 2011, 01:42 AM
I would also like to know how to do this. I cannot seem to work out a way to achieve it.
0
Arun Kumar
Top achievements
Rank 2
answered on 18 May 2011, 01:13 PM
Any Solution? I am also need this.
0
Massimiliano Bassili
Top achievements
Rank 1
answered on 18 May 2011, 01:32 PM
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!
0
Duncan
Top achievements
Rank 1
answered on 01 Sep 2011, 04:58 AM
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
0
Chavdar
Telerik team
answered on 06 Sep 2011, 02:55 PM
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 >>

Tags
General Discussions
Asked by
Marcelo Torres Assis
Top achievements
Rank 1
Answers by
Duncan
Top achievements
Rank 1
Arun Kumar
Top achievements
Rank 2
Massimiliano Bassili
Top achievements
Rank 1
Chavdar
Telerik team
Share this question
or