发送动态表或分区的内容作为电子邮件的主体内容 [英] send dynamic table or div content as an email body content
问题描述
我有一个网页( SomePage.aspx页面
),我需要将已生成的电子邮件体内的含量
< DIV ID =DV_TimeReportWraper=服务器的风格=显示:块>
<表ID =TBL_UsersinTblTime>
&所述; TR的id =TR_UsersinTblTime>
< TD ID =TD_H_Name级=DG>
名称
< / TD>
< TD ID =TD_H_UserID级=DG>
ID
< / TD>
< TD ID =TD_H_Status级=DG>
初期
< / TD>
< TD ID =TD_H_SignOutAutoExeState级=DG>
当前阶段
< / TD>
< / TR>
<%
如果(EDATA!= NULL)
对于(INT IDX = 0; IDX< edata.Count; IDX ++){
VAR行= EDATA [IDX]
布尔bgcl =(IDX%2)== 0;
字符串BgCol =;
如果(bgcl)
BgCol =#70878F;
其他
BgCol =#E6E6B8;
%>
< TR风格=背景颜色:LT;%= BgCol%>>
&所述; TD的id =TD_Name>
<%=行[名称]%>
< / TD>
&所述; TD的id =TD_UserID>
<%=行[用户ID]%>
< / TD>
&所述; TD的id =TD_Status>
<%
INT uidForSrc = Convert.ToInt32(行[用户ID]);
字符串SRC =图像/ SignedOutNoFrame.png;
如果(UserDidnotSignOutTimeOut(uidForSrc))
SRC =图像/ didnotSignOut.png;
%>
<输入类型=形象SRC =<%= SRC%>中风格=宽度:25像素/>
< / TD>
&所述; TD的id =TD_SignOutAutoExeState>
<%
字符串EexcSrc =;
字符串inputType =隐藏;
//这个更新,如果需要的话返回true =需要更新错误=是不需要
如果(UpdatedTimeOutOKForUSER(uidForSrc))
{
inputType =形象;
excSrc =/images/SignedOutNoFrame.png;
}
%>
&其中;输入类型=&其中;%= inputType%>中的src =&其中;%= EexcSrc%>中风格=宽度:25像素/>
< / TD>
< / TR>
<%
如果(IDX == edata.Count - 1)
sendLog();
}
%>
< /表>
< / DIV>
$ C $下 sendLog()
公共无效sendLog()
{
mail.aReciver =username@gmail.com;
mail.bSubject =t检验;
mail.cBody = DV_UsersInTblTime.InnerHtml;
mail.HentalSend();
}
我不能让内容的价值分配 mail.cBody
用。
它说一些有关的价值不是一个文字等等。
这是我使用中正常工作,直到最后尝试添加的页面内容的功能为一体的外部类中的方法,怎么可能实现的结果需要在这里?
公共静态类邮件
{
公共静态字符串aReciver,bSubject,cBody;
公共静态无效HentalSend()
{
字符串SMTPSERVER =smtp.gmail.com;
INT端口= 587;
字符串发件人=Sender@domain.com;
字符串ReCiver = aReciver;
字符串主题= bSubject;
绳体= cBody;
串账户=mail@domain.com;
字符串传递=123456;
发送(SMTPSERVER,端口,账号,通行证,发件人,收件人,主题,正文);
... //发送()是另一个相关的方法对这个问题,它的邮件设置休息
}
}
这code会得到你的动态控制生成的HTML到一个字符串变量。
StringBuilder的StringBuilder的=新的StringBuilder();
StringWriter的作家=新的StringWriter(StringBuilder的);
的HtmlTextWriter的HTMLWriter =新的HtmlTextWriter(作家);
尝试 {
DV_TimeReportWraper.RenderControl(的HTMLWriter);
}赶上(HttpException generatedExceptionName){
}
字符串DV_TimeReportWraper_innerHTML = stringBuilder.ToString;
然后只需使用 DV_TimeReportWraper_innerHTML
作为您的电子邮件的正文
您可能需要创建一个循环的情况下,这个控制有孩子的控制。更多关于这里:<一href="http://msdn.microsoft.com/en-us/library/htwek607.aspx#Y472">http://msdn.microsoft.com/en-us/library/htwek607.aspx#Y472
I have a page (somePage.aspx
) and I need the content that has been generated as an Email body
<div id="DV_TimeReportWraper" runat="server" style="display:block">
<table id="TBL_UsersinTblTime">
<tr id="TR_UsersinTblTime">
<td id="TD_H_Name" class="Dg">
name
</td>
<td id="TD_H_UserID" class="Dg">
ID
</td>
<td id="TD_H_Status" class="Dg">
initial Stage
</td>
<td id="TD_H_SignOutAutoExeState" class="Dg">
current Stage
</td>
</tr>
<%
if(edata != null)
for (int idx=0;idx<edata.Count;idx++) {
var row = edata[idx];
bool bgcl = (idx % 2) == 0;
string BgCol = "";
if (bgcl)
BgCol = "#70878F";
else
BgCol = "#E6E6B8";
%>
<tr style=" background-color:<%=BgCol%>">
<td id="TD_Name">
<% = row["name"] %>
</td>
<td id="TD_UserID">
<%= row["UserId"]%>
</td>
<td id="TD_Status">
<%
int uidForSrc = Convert.ToInt32(row["UserId"]);
string src = "images/SignedOutNoFrame.png";
if (UserDidnotSignOutTimeOut(uidForSrc))
src = "images/didnotSignOut.png";
%>
<input type="image" src="<% =src %>" style="width:25px" />
</td>
<td id="TD_SignOutAutoExeState" >
<%
string EexcSrc = "";
string inputType ="hidden";
//this updates if needed then returns true= needed update false = isn't need
if (UpdatedTimeOutOKForUSER(uidForSrc))
{
inputType = "image";
excSrc = "/images/SignedOutNoFrame.png";
}
%>
<input type="<%=inputType %>" src="<%=EexcSrc %>" style="width:25px" />
</td>
</tr>
<%
if (idx == edata.Count - 1)
sendLog();
}
%>
</table>
</div>
code for sendLog()
public void sendLog()
{
mail.aReciver="username@gmail.com";
mail.bSubject="ttest";
mail.cBody = DV_UsersInTblTime.InnerHtml;
mail.HentalSend();
}
I can't get the value of content to assign mail.cBody
with.
It's saying something about the value not being a literal etc'.
That is the method I'm using in an external class which works fine till this last attempt to add the functionality of page content as a body, how is it possible to achieve the result as needed here?
public static class mail
{
public static string aReciver, bSubject, cBody;
public static void HentalSend()
{
string SmtpServer = "smtp.gmail.com";
int port = 587;
string sender = "Sender@domain.com";
string ReCiver = aReciver;
string Subject = bSubject;
string Body = cBody;
string account = "mail@domain.com";
string Pass = "123456";
Send(SmtpServer, port, account, Pass, sender, Receiver, Subject, Body);
... //send() is another relevant method to this question, it does rest of mail settings
}
}
This code will get the generated HTML of your dynamic control in to a string variable.
StringBuilder stringBuilder = new StringBuilder();
StringWriter writer = new StringWriter(stringBuilder);
HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);
try {
DV_TimeReportWraper.RenderControl(htmlWriter);
} catch (HttpException generatedExceptionName) {
}
string DV_TimeReportWraper_innerHTML = stringBuilder.ToString;
Then just use DV_TimeReportWraper_innerHTML
as the body of your email
You might have to create a loop in case this control has children controls. More on that here: http://msdn.microsoft.com/en-us/library/htwek607.aspx#Y472
这篇关于发送动态表或分区的内容作为电子邮件的主体内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!