如何将网页表单中提交的信息自动发送到指定邮箱?

看到了.NET 提供System.Web.Mail和System.Net.Mail两个NameSpace,但是用哪一个,两者有何区别,目前不清楚,正在学习中……

=========================================
2006-3-11  更新

这个问题得到了初步解决!下面是code:

<%@ Page Language="C#" %>

<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Net" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        string mailfrom = Request.Form["txtFrom"];
        string mailto = Request.Form["txtTo"];
        string mailsub = Request.Form["txtSub"];
        string mailbody = Request.Form["txaBody"];
       
       
        if ( !Page.IsPostBack )
        {
            try
            {

                Mess(mailfrom, mailto, mailsub, mailbody);
               
                ErrorMessage.Text = "succeed!";
                Info.Text  = "From:"+mailfrom;
                Info1.Text = "To:" + mailto;
                Info2.Text = "Sub:" + mailsub;
                Info3.Text = "Content:" + mailbody;
            }
           catch
           {
                ErrorMessage.Text = "Sorry,Error!";
           }
        }
         
    }
   
    protected void Mess(string from,string to,string subject,string body)
    {
       
        SmtpClient Client = new SmtpClient("mail.zcom.com.cn");
        Client.DeliveryMethod = SmtpDeliveryMethod.Network; //用到了System.Net 命名空间
        Client.Credentials = new NetworkCredential("yourname@domain","password");
       
        MailMessage Message = new MailMessage(from,to,subject,body);
        Message.BodyEncoding = System.Text.Encoding.UTF8;
        //Message.BodyEncoding = System.Text.Encoding.Unicode;
        //Message.SubjectEncoding = System.Text.Encoding.Unicode;
       
        Client.Send(Message);
             
        Message.Dispose();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>邮件测试</title>
</head>
<body>
    <form id="form1" runat="server"  >
        <div>
            <asp:Label ID="ErrorMessage" runat="server"></asp:Label><br />
            <asp:Label ID="Info" runat="server"></asp:Label><br />
            <asp:Label ID="Info1" runat="server"></asp:Label><br />
            <asp:Label ID="Info2" runat="server"></asp:Label><br />
            <asp:Label ID="Info3" runat="server"></asp:Label>
        </div>
    </form>
</body>
</html>

从Form 中获得信息,然后显示发送是否成功!但是发送中文,收到的都是乱码,如果有知道解决办法的朋友请告知,感谢!

转载于:https://www.cnblogs.com/creanlin/archive/2006/03/02/340869.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值