在Asp.Net Web项目中获取Aspx页面的内部HTML电子邮件 [英] Get Inner Html of aspx page in Asp.Net web project for email

查看:51
本文介绍了在Asp.Net Web项目中获取Aspx页面的内部HTML电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ASP.NET ...

我在 popup扩展程序上有一个电子邮件按钮,并希望使用另一个 aspx 页面的内部 html 用于正文,然后在发送之前编辑几个标签.这可能吗?

I have an email button on a popup extender and would like to use the inner html of another aspx page to use for the body, then edit a couple tags before it is sent. Is this possible?

基本上,我正在使用 .Net.Mail.MailMessage 创建一个 HtmlBody ,并希望获取另一页的 html (而不实际呈现页面),而不是在字符串中重新创建页面.

Basically I'm using the .Net.Mail.MailMessage to create an HtmlBody and want to grab the html of another page (without actually rendering the page) as opposed to recreating it in a string.

推荐答案

首先创建html电子邮件不允许使用复杂的html(内部,外部样式和其他控件),请参阅...

First of all creating html emails doesn't allow for complicated html (internal,external styling, and other controls) see...

HTML电子邮件指南

所以我所做的就是使用以下代码创建用于发送电子邮件的html字符串...

So what I did was use the following to create an html string for emailing...

1)创建一个简单的.htm文件作为模板,格式化标准html表(而不是asp:tables)和其他标准html标签中的所有内容.

1) Create a simple .htm file as a template, formatting everything in standard html tables (not asp:tables), and other standard html tags.

2)仅在必要时使用内嵌样式.

2) Only use in-line styling if necessary.

3)然后创建可替换的文本单词或短语以进行替换.您还可以使用注释来替换文本或添加到表格中,请参见下面的标记

3) Then create replacable text words or phrases to replace. You can also use a comment to replace text or for adding to a table see markup below

    <span style="font-size: 16px;">TodaysDate</span>

    <table id="PeopleTable" border="1" cellpadding="3" cellspacing="0" width="720">
        <tr style="font-weight: bold;">
            <td width="100">
                First Name
            </td>
            <td width="100">
                Last Name
            </td>
            <td width="100">
                Phone Number
            </td>
        </tr>
        <!--AddRowsHere-->
    </table>

4)然后,从后面代码中的按钮中,您需要将.htm页作为字符串并将其替换为所需的值

4) Then from a button in code behind you need to get the .htm page as string and replace the text with values you want

 Using sr As New System.IO.StreamReader(Server.MapPath("PeoplePage.htm"))
        GetHtml = sr.ReadToEnd
 End Using
 GetHtml = Replace(GetHtml, "TodaysDate", Now.ToShortDateString)

5)将此字符串返回到.Net.Mail.MailMessage.Body并像往常一样发送出去.确保设置MailMesage.IsBodyHtml = True

5) Return this string to the .Net.Mail.MailMessage.Body and send it out as you normally would. Make sure to set MailMesage.IsBodyHtml = True

您还可以使用StringBuilder创建整个字符串,而无需使用模板.

You could also create the entire string using StringBuilder without using a template.

这篇关于在Asp.Net Web项目中获取Aspx页面的内部HTML电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆