How to grab dynamic html and send it via email?

Suppose I have a dynamic html form generated by MVC view (database data with stylesheet). Then I want to send the same html with email. For example, the result might be something like:

  <div id="DivForPrint">
        <fieldset>
            <legend>Hello</legend>
            <table>
                <tbody><tr>
                    <td>
                        <label for="ID">
                            ID&nbsp;#:</label>
                    </td>
                    <td>
                        <span class="displayData">
                            9
                        </span>
                    </td>
                    <td width="100%"></td>
                    <td>
                        <label>
                            Date:
                        </label>
                    </td>
                    <td width="100px">
                        <span class="displayData">
                            23/09/2009_2:28_PM
                        </span>
                    </td>
                </tr>
            </tbody></table>
        </fieldset>
    </div>

      

How do I receive and send it by email? even I can set something like mail.IsBodyHtml = true; but the stylesheet is not available when sending email

+2


source to share


2 answers


You're right. Style sheets are not available because the vast majority of email clients do not load external content other than images. If you want styled content, it must be created using inline style definitions.



I found this rather intimidating tool that converts style definitions and their associated HTML to inline style definitions.

+1


source


I'm sure you can get the output of the View by calling the ViewResult method View.Render () and then looking at the text that was passed.



This is entirely my hypothesis.

+1


source







All Articles