当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  用ASP.Net发送MailList(2)

 用ASP.Net发送MailList(2)

点击次数:25 次 发布日期:2008-11-26 14:38:02 作者:源代码网
源代码网推荐      好了,这个过程就是一个完整的SMTP的过程,下面我们就来看看 豆腐 用 C# 做的这个发送Mail的工具
源代码网推荐  
源代码网推荐    <%@ Assembly Name="System.net" %>
源代码网推荐  
源代码网推荐    <%@ Import Namespace="System.Net" %>
源代码网推荐  
源代码网推荐    <% @Import Namespace="System.Net.Sockets" %>
源代码网推荐  
源代码网推荐    <%@ Import Namespace="System.IO" %>
源代码网推荐  
源代码网推荐    <script language="C#" runat=server>
源代码网推荐  
源代码网推荐     protected void SendMailClick(Object Src, EventArgs E){
源代码网推荐  
源代码网推荐      String smtpserver=txtSmtpserver.Text; file://smtp服务器的IP地址
源代码网推荐  
源代码网推荐      TCPClient tcpc = new TCPClient();
源代码网推荐  
源代码网推荐      if (0 == tcpc.Connect(smtpserver, txtPort.Text.ToInt16()))
源代码网推荐  
源代码网推荐       {
源代码网推荐  
源代码网推荐        file://连接smtp 服务器成功
源代码网推荐  
源代码网推荐        Stream s;
源代码网推荐  
源代码网推荐        StreamReader sr ;
源代码网推荐  
源代码网推荐        String strCmd;
源代码网推荐  
源代码网推荐  
源代码网推荐        Byte[] arrCmd;
源代码网推荐  
源代码网推荐        String strRet;
源代码网推荐  
源代码网推荐        String[] arrRet;
源代码网推荐  
源代码网推荐        sr = new StreamReader(tcpc.GetStream(), Encoding.Default);
源代码网推荐  
源代码网推荐        strRet=sr.ReadLine() + "<br>"; file://mail server 的欢迎语
源代码网推荐  
源代码网推荐        file://服务器连接成功以后,首先向服务器发送HeLo命令
源代码网推荐  
源代码网推荐        strCmd="HELO www.ASP888.net";
源代码网推荐  
源代码网推荐        strRet=strRet + SenSmtpCmd(tcpc,strCmd) + "<br>";
源代码网推荐  
源代码网推荐        file://然后向服务器发送信件的成员的信箱
源代码网推荐  
源代码网推荐        strCmd="mail from:"+ sender.Text;
源代码网推荐  
源代码网推荐        strRet=strRet + SenSmtpCmd(tcpc,strCmd) + "<br>";
源代码网推荐  
源代码网推荐        file://向服务器发送收件人的信箱
源代码网推荐  
源代码网推荐        strCmd="rcpt to:" + receive.Text;
源代码网推荐  
源代码网推荐        strRet=strRet + SenSmtpCmd(tcpc,strCmd) + "<br>";
源代码网推荐  
源代码网推荐        file://所有的准备工作都已经作好了,下面开始进行邮件的部分
源代码网推荐  
源代码网推荐        strCmd="data";
源代码网推荐  
源代码网推荐        strRet=strRet + SenSmtpCmd(tcpc,strCmd) + "<br>";
源代码网推荐  
源代码网推荐        file://邮件内容
源代码网推荐  
源代码网推荐        strCmd="Date: 1234567 ";
源代码网推荐  
源代码网推荐        strCmd=strCmd+"From:" + sender.Text +" ";
源代码网推荐  
源代码网推荐        strCmd=strCmd+"To:" + receive.Text +" ";
源代码网推荐  
源代码网推荐        strCmd=strCmd+"Subject:" + subject.Text +" ";
源代码网推荐  
源代码网推荐        strCmd=strCmd + content.Text +" ";
源代码网推荐  
源代码网推荐        strRet=strRet + SenSmtpCmd1(tcpc,strCmd) + "<br>";
源代码网推荐  
源代码网推荐        strCmd=" . ";
源代码网推荐  
源代码网推荐        strRet=strRet + SenSmtpCmd(tcpc,strCmd) + "<br>";
源代码网推荐  
源代码网推荐        /*strCmd=strCmd+"From:xuexh@haitai.com.cm ";
源代码网推荐  
源代码网推荐        strCmd=strCmd+"To:xuexh@haitai.com.cn ";
源代码网推荐  
源代码网推荐        strCmd=strCmd+"subject:这是一个测试的邮件 ";
源代码网推荐  
源代码网推荐        strCmd=strCmd+" ";
源代码网推荐  
源代码网推荐        strCmd=strCmd+"这些是测试邮件的邮件内容 ";
源代码网推荐  
源代码网推荐        strCmd=strCmd+" . ";
源代码网推荐  
源代码网推荐        *///strRet=strRet + SenSmtpCmd(tcpc,strCmd) + "<br>";
源代码网推荐  
源代码网推荐        file://最后 关闭与smtp 服务器的连接
源代码网推荐  
源代码网推荐        tcpc.Close();
源代码网推荐  
源代码网推荐        showmsg.Text=strRet;
源代码网推荐  
源代码网推荐       }
源代码网推荐  
源代码网推荐      else
源代码网推荐  
源代码网推荐       {
源代码网推荐  
源代码网推荐        showmsg.Text="对不起,连接服务器失败";
源代码网推荐  
源代码网推荐       }
源代码网推荐  
源代码网推荐     }
源代码网推荐  
源代码网推荐     String SenSmtpCmd(TCPClient tcpc,String strCmd){
源代码网推荐  
源代码网推荐     file://为了程序的简单可读,特意写了这个函数
源代码网推荐  
源代码网推荐      Byte[] arrCmd;
源代码网推荐  
源代码网推荐      String strRet;
源代码网推荐  
源代码网推荐      StreamReader sr;
源代码网推荐  
源代码网推荐      Stream s;
源代码网推荐  
源代码网推荐      s=tcpc.GetStream();
源代码网推荐  
源代码网推荐      strCmd = strCmd + " ";
源代码网推荐  
源代码网推荐      arrCmd= Encoding.Default.GetBytes(strCmd.ToCharArray());
源代码网推荐  
源代码网推荐      s=tcpc.GetStream();
源代码网推荐  
源代码网推荐      s.Write(arrCmd, 0, strCmd.Length);
源代码网推荐  
源代码网推荐      sr = new StreamReader(tcpc.GetStream(), Encoding.Default);
源代码网推荐  
源代码网推荐      strRet=sr.ReadLine();
源代码网推荐  
源代码网推荐      return strRet;
源代码网推荐  
源代码网推荐     }
源代码网推荐  
源代码网推荐     String SenSmtpCmd1(TCPClient tcpc,String strCmd){
源代码网推荐  
源代码网推荐      file://为了程序的简单可读,特意写了这个函数
源代码网推荐  
源代码网推荐     Byte[] arrCmd;
源代码网推荐  
源代码网推荐     String strRet;
源代码网推荐  
源代码网推荐     StreamReader sr;
源代码网推荐  
源代码网推荐     Stream s;
源代码网推荐  
源代码网推荐     s=tcpc.GetStream();
源代码网推荐  
源代码网推荐     strCmd = strCmd;
源代码网推荐  
源代码网推荐     arrCmd= Encoding.Default.GetBytes(strCmd.ToCharArray());
源代码网推荐  
源代码网推荐     s=tcpc.GetStream();
源代码网推荐  
源代码网推荐     s.Write(arrCmd, 0, strCmd.Length);
源代码网推荐  
源代码网推荐     return "";
源代码网推荐  
源代码网推荐    }
源代码网推荐  
源代码网推荐    </script>
源代码网推荐  
源代码网推荐    <form id=testForm runat=server>
源代码网推荐  
源代码网推荐    <asp:label id=showmsg runat=server /><br>
源代码网推荐  
源代码网推荐     SMTP服务器:<asp:TextBox id=txtSmtpserver runat=server /><asp:TextBox id=txtPort Text=25 runat=server /><br>
源代码网推荐  
源代码网推荐     发信人:<asp:TextBox id=sender runat=server />
源代码网推荐  
源代码网推荐    <br>
源代码网推荐  
源代码网推荐     收信人:<asp:TextBox id=receive runat=server />
源代码网推荐  
源代码网推荐    <br>
源代码网推荐  
源代码网推荐     信件主题:<asp:TextBox id=subject runat=server />
源代码网推荐  
源代码网推荐    <br>
源代码网推荐  
源代码网推荐     信件内容:<asp:TextBox id=content runat=server TextMode=MultiLine rows=10/>
源代码网推荐  
源代码网推荐     <asp:Button Text="发送" id=SendMail onClick=SendMailClick runat=server />
源代码网推荐  
源代码网推荐    </form>
源代码网推荐  
源代码网推荐    大家可能在看这段程序的时候已经发现了这样的两个函数SenSmtpCmd和SenSmtpCmd1,这两个函数的作用是SenSmtpCmd1不接收smtp server 传递回来的回应,主要是目前的这个版本的ASP.NET 在处理中文的时候还是存在一定的Bug,所以就只有采取这样的变通的办法了。
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华