How can I save the html generated by the javascript code so that it can be sent via email?

I would like to convert a C # API I wrote that generates (static) html pages (mainly for displaying data tables) using angularjs. The goal is to better separate data and html, allowing interactivity (like sorting by column) / data reuse that is beyond what a static html page has to offer.

Now the problem is that once I use JS to generate a portion of my page, I can no longer send the html document as is by email because the JS will not be executed from the email client. However, this is a useful feature of my API.

Is there a way to get around this?

I think I once heard a mention of a virtual browser (in node?) That could execute all javascript (no GUI) and then dump the html to a file.

Otherwise, the only solution I could think of is that C # generates tables by hardcoding the values ​​into html (as currently) and have angular values ​​that still do all the json post-processing to allow user interact with data. It's a shame that this would require duplicating some of the table building logic in C # and JS, which is not very convenient.

+3


source to share


2 answers


If you want to send an email, then execute a service in Angular that calls some function on the server side to send the email, The data has to be passed as some view model. In ASP.NET, this server side functionality is often exposed through a Web API or a generic handler (.ashx).

If you would like the user to be able to download the file directly from the page, see How to trigger file download on html or javascript button click .



It should be noted that direct use of HTML targeting a web page is often discouraged from including in email. The HTML parser in email clients is very different, and for compatibility you should probably only use a small subset of HTML functionality. HTML targeting the browser also often contains additional content (such as navigation menus) that is inappropriate for email.

+1


source


Will I be using the Mailing API for consideration? In this case, you can just grab the content and use angular to send it to e. Mr. Sendgrid.



+1


source







All Articles