人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

August 31, 2006

把页面内容作为Email发出

Filed under: ASP.NET

思路:在button的client click中把页面的内容存到一个hidden filed中,在server端的click中读取并发送
asp:Button ID=”Button_SendMail” runat=”server” Text=”SendEmail” OnClientClick=”CellPostBack();” OnClick=”Button_SendMail_Click”

function CellPostBack()
{
var result = document.getElementById(”result”);
var hiddenInfo = document.getElementById(”hiddenInfo”);
//alert(result.innerText);
//hiddenInfo.value = result.innerHTML;
}
protected void Button_SendMail_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.hiddenInfo.Value))
this.SendMail(this.hiddenInfo.Value);
}
private void SendMail( string body)
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress(”aloneplayer@gmail.com“, “aLONEPLayer”);

smtpClient.Host = “XXXXX”;
//smtpClient.Port = 25;
message.From = fromAddress;
message.To.Add(”aloneplayer@gmail.com“);
message.Subject = “Hi, I’am Riven”;
message.IsBodyHtml = true;
message.Body = body;
smtpClient.Send(message);
}
还需要关闭Asp.net对页面内容的校验
<pages validateRequest=”false”/>

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2006/08/31/p163/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham