一个简单的基于System.Web.Mail的ASP.Net邮件发送程序

这里就是一个简单的asp.net网页了,代码很简单,直接copy到记事本里面保存为*.aspx文件就可以用了。本人已经测试过,可以使用
<% @ Page Language = " C# "   %>
<% @ Import Namespace = " System.Web.Mail "   %>  

<! DOCTYPE HTML PUBLIC  " -//W3C//DTD HTML 4.01 Transitional//EN "
" http://www.w3.org/TR/html4/loose.dtd " >
< html >
< head >
< meta http - equiv = " Content-Type "  content = " text/html; charset=gb2312 " >
< title > ASP.Net发送Email </ title >
< script language = " c# "  runat = " server " >
public   void  sub_Click(Object src,EventArgs e)
{
    MailMessage MyMail 
= new MailMessage();
    
    
//收信人
    MyMail.To = Request.Form["mailto"];
    
//抄送
    MyMail.Cc = Request.Form["mailcc"];
    
//密送
    MyMail.Bcc = Request.Form["mailbcc"];

    
    
//附件
    
//if("" != Request.Form["mailattachments"])
//    {
//        MailAttachment myAttachment = new MailAttachment(Request.Form["mailattachments"], MailEncoding.Base64);
//        MyMail.Attachments.Add(myAttachment);
//    }
    
    
    
//发信人
    MyMail.From = Request.Form["mailfrom"];
    
//标题
    MyMail.Subject = Request.Form["mailsubject"];
    
//信体
    MyMail.Body = Request.Form["mailbody"];
    
//优先级
    MyMail.Priority = MailPriority.Low;
    
    
//设置支持服务器验证
    MyMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate""1");
    
//设置用户名
    MyMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Request.Form["mailuser"]);
    
//设置用户密码
    MyMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Request.Form["mailpassword"]);
    
    
    SmtpMail.SmtpServer 
=  Request.Form["mailsmtp"];
    SmtpMail.Send(MyMail);
    
    Response.Write(Request.Form[
"mailto"]);
}

</ script >
< style >
body
{
    text
-decoration:1.5;
    font
-size:10pt;
}

td
{
    border: 1px solid #cccccc;
}

</ style >
</ head >

< body >
< form action = ""  method = " post "  enctype = " multipart/form-data "  name = " formmail "  runat  =  server >
      
< table width = " 760 "  border = " 0 "  align = " center "  cellpadding = " 0 "  cellspacing = " 0 " >
        
< tr >
          
< td width = " 14% "  rowspan = " 3 " > 收信人设置 </ td >
          
< td width = " 10% " > 收信人: </ td >
          
< td width = " 76% " >< input name = " mailto "  type = " text "  id = " mailto "  value = " fandongwei@gmail.com "  size = " 30 " ></ td >
        
</ tr >
        
< tr >
          
< td > 抄送: </ td >
          
< td >< input name = " mailcc "  type = " text "  id = " mailcc "  value = " fandongwei@126.com "  size = " 30 " ></ td >
        
</ tr >
        
< tr >
          
< td > 密送: </ td >
          
< td >< input name = " mailbcc "  type = " text "  id = " mailbcc "  value = " fandongwei1@126.com "  size = " 30 " ></ td >
        
</ tr >     
        
< tr >
          
< td width = " 14% "  rowspan = " 4 " > 发信人设置 </ td >
          
< td width = " 10% " > 发信人: </ td >
          
< td width = " 76% " >< input name = " mailfrom "  type = " text "  id = " mailfrom "  value = " fandongwei1 "  size = " 30 " ></ td >
        
</ tr >
        
< tr >
          
< td > smtp地址: </ td >
          
< td >< input name = " mailsmtp "  type = " text "  id = " mailsmtp "  value = " smtp.126.com "  size = " 30 " ></ td >
        
</ tr >
        
< tr >
          
< td > 帐号: </ td >
          
< td >< input name = " mailuser "  type = " text "  id = " mailuser "  value = " 你的帐号 "  size = " 30 " ></ td >
        
</ tr >
        
< tr >
          
< td > 密码:  </ td >
          
< td >< input name = " mailpassword "  type = " password "  id = " mailpassword "  value = " 你的帐号密码 "  size = " 32 " ></ td >
        
</ tr >
        
< tr >
          
< td colspan = " 2 "  rowspan = " 2 " > 附件: </ td >
          
< td >& nbsp; </ td >
        
</ tr >
        
< tr >
          
< td >              < input name = " mailattachments "  type = " file "  id = " mailattachment "  size = " 50 " ></ td >
        
</ tr >
        
< tr >
          
< td colspan = " 2 " >  标题 </ td >
          
< td >< input name = " mailsubject "  type = " text "  id = " mailpassword3 "  value = " 标题 "  size = " 50 " ></ td >
        
</ tr >
        
< tr >
          
< td colspan = " 3 " > 信体: </ td >
        
</ tr >
        
< tr >
          
< td colspan = " 3 "  align = " left "  valign = " middle " >< textarea name = " mailbody "  cols = " 80 "  rows = " 15 "  id = " mailbody " > 信体 </ textarea >
            
& nbsp;
                    
< asp:Button id = " sub "  Text = " 发送 "  Type = " submit "  runat = server OnClick = " sub_Click "   />

            
</ td >
        
</ tr >
        
< tr >
          
< td colspan = " 3 " >& nbsp; </ td >
        
</ tr >
  
</ table >
</ form >
</ body >
</ html >
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值