在按钮上通过电子邮件发送aspx页面 [英] email an aspx page on a button click

查看:95
本文介绍了在按钮上通过电子邮件发送aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两个aspx页面,分别是1.aspx和2.aspx,在1.aspx页面中我有一个按钮,单击该按钮后页面将重定向到下一页,即2.aspx带有1.aspx页面的值. 2.aspx页是完全用后面的代码设计的.现在的重点是,在2.aspx页中我有一个按钮,现在我想使用该按钮将此2.aspx页邮寄到电子邮件ID. div class ="h2_lin">解决方案

尝试类似的方法:

电子邮件验证:

 <   system.net  > 
     <  邮件设置 > 
<   smtp  > 
<  网络    ="   smtp.domain.com"   端口  ="  25" 用户名   user@domain.com" 密码  ="  / <  /smtp  > 
     <  /mailsettings  > 
<  /system.net  >  



 字符串 html = 字符串 .Empty;
尝试
{
   WebClient web =  WebClient();
   字节 []字节;
   // 将网址更改为:http://localhost:10101/2.aspx 
   字节= web.DownloadData(" );
   UTF8Encoding oUTF8 =  UTF8Encoding();
   // 获取从页面/URL返回的html 
   html = oUTF8.GetString(bytes);
   
   // 发送消息
   MailMessage邮件=  MailMessage("   receiver@mail.com");
   SmtpClient smtp =  SmtpClient();
   mail.Subject = " ;
   mail.Body = html;
   mail.IsBodyHtml =  true ; // 它表示电子邮件客户端应将此呈现为html 
   smtp.Send(mail); //  ...,然后发送!
}
捕获(例外)
{
   向上; // 相应地处理您的错误,或者直接处理.
} 



祝...结束,
莫尔斯


Hi,

I have two aspx pages say, 1.aspx and 2.aspx, in 1.aspx page i have a button on clicking the button the page will redirect to the next page i.e., 2.aspx carrying the values of 1.aspx page. This 2.aspx page is totally designed in code behind. now the point is, in 2.aspx page i have a button, now i want to mail this 2.aspx page to an email id using that button.. how can i do this, please help me out fnds....

解决方案

Try something like:

Email Authentication:

<system.net>
     <mailsettings>
	 <smtp>
	     <network host="smtp.domain.com" port="25" username="user@domain.com" password="


0M3Pa@


5w0D" /> </smtp> </mailsettings> </system.net>



String html = String.Empty;
try
{
   WebClient web = new WebClient();
   Byte[] bytes;
   // Change url to maybe: http://localhost:10101/2.aspx
   bytes = web.DownloadData( "http:www.domain.com/page.aspx" );
   UTF8Encoding oUTF8 = new UTF8Encoding();
   // Get the html returned from the page/url
   html = oUTF8.GetString( bytes );
   
   // Send the message
   MailMessage mail = new MailMessage( "sender@mail.com", "receiver@mail.com" );
   SmtpClient smtp = new SmtpClient();
   mail.Subject = "Message Subject";
   mail.Body = html;
   mail.IsBodyHtml = true; // It says e-mail clients should render this as html
   smtp.Send( mail ); // ... and, send it!
}
catch( Exception up )
{
   throw up; // Handle your errors accordingly, or leave as is to throw up.
}



Happy ...ending,
Morgs


这篇关于在按钮上通过电子邮件发送aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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