简体   繁体   English

是否可以在 email 正文中发送一个 aspx 页面?

[英]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这些图像是在运行时决定的,无论如何将它嵌入到 email 主体中

please help请帮忙

If you only want that part of the markup in the email, then put it inside a user control (myEmailControl.ascx).如果您只想要 email 中的那部分标记,则将其放在用户控件 (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.然后,您可以从发送 email 的脚本调用控件上的 Render() 并拦截控件的 html output。 Then you can put that html into an email body.然后你可以将 html 放入 email 主体中。 (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) (您的图片还需要绝对网址,以便它们显示在 email 中,但我相信您已经想到了)

Page/Handler that sends the email:发送 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:您可以从页面下载呈现的 HTML 并发送:

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.现在你可以在你的html中发送 html 的内容。

Your best bet is probably to output the images as a Base 64 in the HTML.您最好的选择可能是将 output 图像作为 HTML 中的 Base 64。

<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!在后面的代码中,获取图像,将其转换为 Base 64 并将其打印为 src!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM