感觉在学校课本的学的那些邮箱收发系统挺麻烦,又要配置stmp ,pop 啥的好麻烦,所以自己就写了个,供大家点评。
效果图:
前台代码:- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <style type="text/css">
- .style1 {
- height: 23px;
- }
- .style2
- {
- height: 25px;
- }
- .style3
- {
- height: 20px;
- }
- </style>
- </head>
- <body>
- <form id="form1" method="post" runat="server">
- <div>
- <fieldset>
- <legend >SMTP配置</legend>
- <table width="100%">
- <tr><td class="item_title" colspan="2">STMP服务器</td></tr>
- <tr>
- <td class="style2">
-
- <asp:TextBox ID="smtp" runat="server" Width="148px" >smtp.qq.com</asp:TextBox>
-
- </td>
- <td class="style2">设置发送邮件的SMTP服务器地址</td>
- </tr>
- <tr><td class="item_title">系统邮箱名称</td></tr>
- <tr>
- <td class="vtop rowform">
- <asp:TextBox ID="sysemail" runat="server">1350869348@qq.com</asp:TextBox>
- </td>
- <td class="vtop">设置发送邮件的邮箱地址</td>
- </tr>
- <tr><td class="item_title">系统邮箱密码</td></tr>
- <tr>
- <td class="vtop rowform">
- <asp:TextBox ID="password" runat="server" TextMode="Password"></asp:TextBox>
- </td>
- <td class="vtop">设置邮件的密码</td>
- </tr>
- <tr><td class="style3">SMTP端口</td></tr>
- <tr>
- <td class="vtop rowform">
- <asp:TextBox ID="port" runat="server">25</asp:TextBox>
- </td>
- <td class="vtop">设置STMP端口</td>
- </tr>
- <tr><td class="item_title">用户名</td></tr>
- <tr>
- <td class="style1">
- <asp:TextBox ID="userName" runat="server"></asp:TextBox>
- </td>
- <td class="style1">设置邮箱的用户名</td>
- </tr>
- <tr><td class="item_title">发送内容</td></tr>
- <tr>
- <td class="style1">
- <asp:TextBox ID="txtContent" runat="server"></asp:TextBox>
- </td>
- <td class="style1">发送内容</td>
- </tr>
- <tr><td class="item_title">接收邮件的用户</td></tr>
- <tr>
- <td class="vtop rowform">
- <asp:TextBox ID="testEmail" runat="server"></asp:TextBox>
- <asp:Button ID="sendTestEmail" runat="server" Text="Button"
- onclick="sendTestEmail_Click" />
- </td>
- <td class="vtop">发送邮件<asp:Label ID="Label1" runat="server"></asp:Label>
- </td>
- </tr>
- </table>
- </fieldset>
- </div>
- </form>
- </body>
- </html>
复制代码 后台代码:- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Net;
- using System.Net.Mail;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
-
- //MailMessage mail = new MailMessage();
- //SmtpAccess client = new SmtpAccess();
-
- }
- public void GerSmtpEmailPlugIn(string filepath)
- {
-
- }
- protected void sendTestEmail_Click(object sender, EventArgs e)
- {
- MailMessage mm = new MailMessage();
- mm.From = new MailAddress(sysemail.Text);
- //mm.To.Add(new MailAddress(testEmail.Text));
- mm.Subject = "测试邮件";
- // mm.Body = "快点出来啦 !!";
- mm.Body = txtContent.Text;
- string[] emailarry = testEmail.Text.Split(',');
- for (int i = 0; i < emailarry.Length; i++)
- {
- mm.CC.Add(new MailAddress(emailarry[i]));
- SmtpClient client = new SmtpClient();
- client.Host = smtp.Text;
- client.Port = int.Parse(port.Text);
- client.Credentials = new NetworkCredential(sysemail.Text, password.Text);
- client.Send(mm);
- }
- //mm.CC.Add(new MailAddress(testEmail.Text));
- Label1.Text = "发送成功";
- }
- }
复制代码 附件:
邮件.rar
(6.01 KB, 下载次数: 80)
|