用ASP.Net发送MailList(3)
点击次数:24 次 发布日期:2008-11-26 14:37:58 作者:源代码网
|
源代码网推荐 源代码网推荐 <%@ 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() + " 源代码网推荐 "; 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:" + receive2.Text; 源代码网推荐 源代码网推荐 strRet=strRet + SenSmtpCmd(tcpc,strCmd) + "<BR>"; 源代码网推荐 源代码网推荐 file://邮件列表的发送工作,其实就是打开一次Socket连接,发送多个mail的结果 源代码网推荐 源代码网推荐 strCmd="rcpt to:" + receive1.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:" + receive1.Text + ";" + receive2.Text +" "; 源代码网推荐 源代码网推荐 file://strCmd=strCmd+"To:" + receive1.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 ""; 源代码网推荐 源代码网推荐 } 源代码网推荐 源代码网推荐 源代码网推荐 源代码网推荐 <FORM id=testForm runat="server"> 源代码网推荐 源代码网推荐 <?XML:namespace prefix = asp /><asp:label id=showmsg runat="server"></asp:label> 源代码网推荐 源代码网推荐 SMTP服务器:<asp:TextBox id=txtSmtpserver runat="server"></asp:TextBox><asp:TextBox id=txtPort runat="server" Text="25"></asp:TextBox> 源代码网推荐 源代码网推荐 发信人:<asp:TextBox id=sender runat="server"></asp:TextBox> 源代码网推荐 源代码网推荐 收信人1:<asp:TextBox id=receive1 runat="server"></asp:TextBox> 源代码网推荐 源代码网推荐 收信人2:<asp:TextBox id=receive2 runat="server"></asp:TextBox> 源代码网推荐 源代码网推荐 信件主题:<asp:TextBox id=subject runat="server"></asp:TextBox> 源代码网推荐 源代码网推荐 信件内容:<asp:TextBox id=content runat="server" TextMode="MultiLine" rows="10/"> 源代码网推荐 源代码网推荐 <asp:Button id=SendMail onclick=SendMailClick runat="server" Text="发送"></asp:Button> 源代码网推荐 源代码网推荐 </FORM> 源代码网推荐 源代码网推荐 源代码网推荐 </asp:TextBox> 源代码网推荐 做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。 源代码网推荐 源代码网供稿. |
