Is it possible to send an aspx page in email body?

<div class="popup-holder">
            <div class="popup-frame">
                <div class="container">
                    <div class="mail-block">
                        <div class="mail-holder">
                            <strong class="mail-logo"><a href="#">abc website</a></strong>
                            <div class="mail-page">
                                <div class="mail-page-holder">
                                    <div class="mail-page-frame">
                                        <p>Hello &lt;<asp:Label ID="lblfriend" runat="server" Text="Label"></asp:Label>>!,</p>
                                        <p>Great News!  &lt;One of your FB Friends/<asp:Label ID="lblmyname" runat="server" Text="Label"></asp:Label>>  has invited you to BlissLink.</p>
                                        <p>(<asp:Label ID="lblmyname1" runat="server" Text="Label"></asp:Label>) says:  &lt;<asp:Label
                                            ID="lblmess" runat="server" Text="abc is fun ,"></asp:Label>><br /><br /></p>
                                        <p></p>
                                        <ul class="f-list">
                                            <li>
                                                <asp:Image ID="Image3" runat="server" width="48" height="48" />
                                                <strong class="title"><span><asp:Label ID="Label2" runat="server" ></asp:Label></span></strong>
                                            </li>
                                            <li>
                                                <asp:Image ID="Image4" runat="server" width="48" height="48" />
                                                <strong class="title"><span> 
                                                    <asp:Label ID="Label3" runat="server" ></asp:Label></span></strong>
                                            </li>
                                            <li>
                                                <asp:Image ID="Image5" runat="server" width="48" height="48" />
                                                <strong class="title"><span><asp:Label ID="Label4" runat="server" ></asp:Label></span></strong>
                                            </li>
                                            <li>
                                                <asp:Image ID="Image6" runat="server" width="48" height="48" />
                                                <strong class="title"><span><asp:Label ID="Label5" runat="server" ></asp:Label></span></strong>
                                            </li>
                                            <li>
                                                <asp:Image ID="Image7" runat="server" width="48" height="48" />
                                                <strong class="title"><span> <asp:Label ID="Label6" runat="server"></asp:Label></span></strong>
                                            </li>
                                            <li>
                                                <asp:Image ID="Image8" runat="server" width="48" height="48" />
                                                <strong class="title"><span> <asp:Label ID="Label7" runat="server" ></asp:Label></span></strong>
                                            </li>
                                            <li>
                                                <asp:Image ID="Image9" runat="server" width="48" height="48" />
                                                <strong class="title"><span><asp:Label ID="Label8" runat="server" ></asp:Label></span></strong>
                                            </li>
                                            <li>
                                                <asp:Image ID="Image10" runat="server" width="48" height="48" />
                                                <strong class="title"><span> <asp:Label ID="Label9" runat="server" ></asp:Label></span></strong>
                                            </li>
                                            <li>
                                                <asp:Image ID="Image11" runat="server" width="48" height="48" />
                                                <strong class="title"><span><asp:Label ID="Label10" runat="server" ></asp:Label></span></strong>
                                            </li>
                                            <li>
                                                <asp:Image ID="Image12" runat="server" width="48" height="48" />
                                                <strong class="title"><span><asp:Label ID="Label11" runat="server" ></asp:Label></span></strong>
                                            </li>
                                        </ul>
                                        <asp:Button ID="Button6" runat="server" Text="Expand Your Network"  CssClass="btn" />
                                        <span class="bot-text">Cheers,<br />Your abc Team</span>
                                    </div>
                                </div>
                            </div>
                            <span class="un">If you have no more interest in receiving our news, <a href="#">unsubscribe.</a></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>

these images are decided at runtime is there anyway of embedding it in the email body

please help

Answers


If you only want that part of the markup in the email, then put it inside a user control (myEmailControl.ascx). You can then call Render() on the control from the script that sends the email and intercept the html output of the control. Then you can put that html into an email body. (Your images will also need absolute urls so that they show up in the email, but I'm sure you've already thought of that)

Page/Handler that sends the email:

    StringBuilder htmlResponse = new StringBuilder();
    using (StringWriter sw = new StringWriter(htmlResponse))
    {
        using (HtmlTextWriter textWriter = new HtmlTextWriter(sw))
        {
            Control emailBody = Page.LoadControl("myEmailControl.ascx");
            emailBody.RenderControl(textWriter);
        }
    }
    string emailHtml = htmlResponse.ToString();

You could download the rendered HTML from the page and send that:

WebRequest request = WebRequest.Create("http://server.com/path/to/page.aspx");
WebResponse response = request.GetResponse();

StringReader reader = new StringReader(response.GetResponseStream());

string html = reader.ReadToEnd();

Now you can just send the contents of html in your email.


Your best bet is probably to output the images as a Base 64 in the HTML.

<img src="data:image/png;base64,iVBrkJggg==" alt="Base 64 encoded!" /> 

In your code behind, get the image, convert it to a Base 64 and print that as the src instead!


Need Your Help