qunFa.aspx文件的代码:

<%...@Pagelanguage="c#"Codebehind="qunFa.aspx.cs"AutoEventWireup="false"Inherits="liuwei.hanmail.qunFa"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<HTML>
<HEAD>
<title>qunFa</title>
<metacontent="MicrosoftVisualStudio.NET7.1"name=GENERATOR>
<metacontent=C#name=CODE_LANGUAGE>
<metacontent=JavaScriptname=vs_defaultClientScript>
<metacontent=http://schemas.microsoft.com/intellisense/ie5name=vs_targetSchema>
</HEAD>
<bodyMS_POSITIONING="GridLayout">
<formid=Form1method=postrunat="server">
<asp:ListBoxid="ListBoxMsg"style="Z-INDEX:118;LEFT:136px;POSITION:absolute;TOP:344px"
runat="server"Width="440px"Height="184px"></asp:ListBox>
<asp:Labelid="Label11"style="Z-INDEX:108;LEFT:120px;POSITION:absolute;TOP:320px"runat="server">信息查看</asp:Label>
<asp:Labelid="Label10"style="Z-INDEX:117;LEFT:112px;POSITION:absolute;TOP:16px"runat="server">SMTP服务器地址</asp:Label>
<asp:Labelid="Label9"style="Z-INDEX:100;LEFT:128px;POSITION:absolute;TOP:48px"runat="server">用户名</asp:Label>
<asp:TextBoxid="TextBoxSrv"style="Z-INDEX:101;LEFT:264px;POSITION:absolute;TOP:24px"
runat="server"Width="240px"></asp:TextBox>
<asp:Labelid="Label8"style="Z-INDEX:102;LEFT:360px;POSITION:absolute;TOP:48px"runat="server">口令</asp:Label>
<asp:TextBoxid="TextBoxUser"style="Z-INDEX:103;LEFT:192px;POSITION:absolute;TOP:48px"
runat="server"Width="152px"></asp:TextBox>
<asp:TextBoxid="TextBoxPwd"style="Z-INDEX:104;LEFT:416px;POSITION:absolute;TOP:48px"
runat="server"Width="168px"TextMode="Password"></asp:TextBox>
<asp:Labelid="Label4"style="Z-INDEX:105;LEFT:128px;POSITION:absolute;TOP:80px"runat="server">发信人</asp:Label>
<asp:Labelid="Label5"style="Z-INDEX:106;LEFT:360px;POSITION:absolute;TOP:80px"runat="server">收信人</asp:Label>
<asp:TextBoxid="TextBoxSend"style="Z-INDEX:107;LEFT:192px;POSITION:absolute;TOP:80px"
runat="server"></asp:TextBox>
<asp:TextBoxid="TextBoxRev"style="Z-INDEX:109;LEFT:416px;POSITION:absolute;TOP:80px"
runat="server"Width="168px"></asp:TextBox>
<asp:Labelid="Label6"style="Z-INDEX:110;LEFT:128px;POSITION:absolute;TOP:112px"runat="server">主题</asp:Label>
<asp:TextBoxid="TextBoxSubject"style="Z-INDEX:112;LEFT:192px;POSITION:absolute;TOP:104px"
runat="server"Width="392px"></asp:TextBox>
<asp:TextBoxid="TextBoxMailText"style="Z-INDEX:113;LEFT:144px;POSITION:absolute;TOP:160px"
runat="server"Width="440px"TextMode="MultiLine"Height="120px"></asp:TextBox>
<asp:Labelid="Label7"style="Z-INDEX:114;LEFT:128px;POSITION:absolute;TOP:136px"runat="server">邮件内容</asp:Label>
<asp:Buttonid="ButtonSend"style="Z-INDEX:115;LEFT:464px;POSITION:absolute;TOP:296px"
runat="server"Text="发送"></asp:Button>
<asp:Labelid="LabelErr"style="Z-INDEX:116;LEFT:696px;POSITION:absolute;TOP:136px"
runat="server"></asp:Label></FORM>
</body>
</HTML>
qunFa.aspx.cs的代码:
usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Web;
usingSystem.Web.SessionState;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;
usingSystem.IO;
usingSystem.Net;
usingSystem.Net.Sockets;
namespaceSendmail
...{
/**////<summary>
///qunFa的摘要说明。
///</summary>
publicclassqunFa:System.Web.UI.Page
...{
protectedSystem.Web.UI.WebControls.LabelLabelErr;
protectedSystem.Web.UI.WebControls.ButtonButtonSend;
protectedSystem.Web.UI.WebControls.LabelLabel7;
protectedSystem.Web.UI.WebControls.TextBoxTextBoxMailText;
protectedSystem.Web.UI.WebControls.TextBoxTextBoxSubject;
protectedSystem.Web.UI.WebControls.LabelLabel6;
protectedSystem.Web.UI.WebControls.TextBoxTextBoxRev;
protectedSystem.Web.UI.WebControls.TextBoxTextBoxSend;
protectedSystem.Web.UI.WebControls.LabelLabel5;
protectedSystem.Web.UI.WebControls.LabelLabel4;
protectedSystem.Web.UI.WebControls.TextBoxTextBoxPwd;
protectedSystem.Web.UI.WebControls.TextBoxTextBoxUser;
protectedSystem.Web.UI.WebControls.LabelLabel8;
protectedSystem.Web.UI.WebControls.TextBoxTextBoxSrv;
protectedSystem.Web.UI.WebControls.LabelLabel9;
protectedSystem.Web.UI.WebControls.LabelLabel11;
protectedSystem.Web.UI.WebControls.ListBoxListBoxMsg;
protectedSystem.Web.UI.WebControls.LabelLabel10;
TcpClientsmtpSrv;
NetworkStreamnetStrm;
stringCRLF=" ";
privatevoidPage_Load(objectsender,System.EventArgse)
...{
}

Web窗体设计器生成的代码#regionWeb窗体设计器生成的代码
overrideprotectedvoidOnInit(EventArgse)
...{
//
//CODEGEN:该调用是ASP.NETWeb窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/**////<summary>
///设计器支持所需的方法-不要使用代码编辑器修改
///此方法的内容。
///</summary>
privatevoidInitializeComponent()
...{
this.ButtonSend.Click+=newSystem.EventHandler(this.ButtonSend_Click);
this.Load+=newSystem.EventHandler(this.Page_Load);
}
#endregion

privatevoidButtonSend_Click(objectsender,System.EventArgse)
...{
this.ListBoxMsg.Items.Clear();
string[]userList=this.TextBoxRev.Text.Split(',');
for(inti=0;i<userList.Length;i++)
Qun(userList[i]);

}
publicvoidQun(stringuserList)
...{
try
...{
stringdata;
smtpSrv=newTcpClient(this.TextBoxSrv.Text,25);
netStrm=smtpSrv.GetStream();
StreamReaderrdStrm=newStreamReader(smtpSrv.GetStream());
this.WriteStream("EHLOLocal");
this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
this.WriteStream("AUTHLOGIN");
this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
data=this.TextBoxUser.Text;
data=AuthStream(data);
this.WriteStream(data);
this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
data=this.TextBoxPwd.Text;
data=AuthStream(data);
this.WriteStream(data);
this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
data="MAILFROM:<"+this.TextBoxSend.Text+">";
this.WriteStream(data);
this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
data="RCPTTO:<"+userList+">";
this.WriteStream(data);
this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
this.WriteStream("DATA");
this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
data="Date:"+DateTime.Now;
this.WriteStream(data);
data="From:"+this.TextBoxSend.Text;
this.WriteStream(data);
data="TO:"+userList;
this.WriteStream(data);
data="SUBJECT:"+this.TextBoxSubject.Text;
this.WriteStream(data);
data="Reply-TO:"+this.TextBoxSend.Text;
this.WriteStream(data);
this.WriteStream("");
this.WriteStream(this.TextBoxMailText.Text);
this.WriteStream(".");
this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
this.WriteStream("QUIT");
this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
netStrm.Close();
rdStrm.Close();
this.LabelErr.Text="发送成功!";
}
catch(Exceptionex)
...{
this.LabelErr.Text=ex.ToString();
}
}
privatevoidWriteStream(stringstrCmd)
...{
strCmd+=CRLF;
byte[]bw=System.Text.Encoding.Default.GetBytes(strCmd);
netStrm.Write(bw,0,bw.Length);
}
privatestringAuthStream(stringstrCmd)
...{
try
...{
byte[]by=System.Text.Encoding.Default.GetBytes(strCmd);
strCmd=Convert.ToBase64String(by);
}
catch(Exceptionerr)
...{
returnerr.ToString();
}
returnstrCmd;
}
群发邮件系统实现
本文介绍了一个基于C#实现的群发邮件系统,通过网页界面配置SMTP服务器、用户名、密码等信息,并支持批量输入收件人地址进行邮件群发。系统采用TCP客户端连接SMTP服务器,实现了登录认证、邮件构建及发送等功能。
2061

被折叠的 条评论
为什么被折叠?



