前台代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <h2>邮件发送系统</h2> <table> <tr> <td> 收件人邮箱地址: </td> <td> <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox> </td> </tr> <tr> <td> 抄送至: </td> <td> <input type="text" id="txtCC" value=" " runat = "server" /> </td> </tr> <tr> <td> 邮件主题: </td> <td> <input type="text" id="txtTheme" value=" " runat = "server" /> </td> </tr> <tr> <td> 邮件内容: </td> <td> <asp:TextBox ID="txtContent" TextMode ="MultiLine" runat="server" Height="98px" Width="214px"></asp:TextBox> </td> </tr> <tr> <td> 添加附件: </td> <td> <asp:FileUpload ID="FileUpload1" runat="server" /> </td> </tr> <tr> <td> </td> <td> <asp:Button ID="btnEmail" runat="server" Text="发送邮件" onclick="btnEmail_Click" /> </td> </tr> </table> </div> </form> </body> </html> 后台代码: protected void btnEmail_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtEmail.Text)) { Response.Write("<script>alert('收件人不能为空');</script>"); } else { try { //声明一个Mail对象 MailMessage mail = new MailMessage(); //发件人地址 mail.From = new MailAddress("。。。。。");//如果是自己则添入自己的邮箱地址 //收件人地址 mail.To.Add(new MailAddress(this.txtEmail.Text)); //邮件主题 mail.Subject = this.txtTheme.Value; //邮件主题编码 mail.SubjectEncoding = System.Text.Encoding.UTF8; //邮件内容 mail.Body = this.txtContent.Text; //邮件内容编码 mail.BodyEncoding = System.Text.Encoding.UTF8; //添加附件 Attachment file = new Attachment(this.FileUpload1.PostedFile.FileName); mail.Attachments.Add(file); //抄送到其他邮箱 mail.CC.Add(new MailAddress(this.txtCC.Value)); //是否为HTML邮件 mail.IsBodyHtml = true; //邮件优先级 mail.Priority = MailPriority.High; //创建一个邮件服务器类 SmtpClient client = new SmtpClient(); client.Host = "SMTP.163.com"; //SMTP服务端口 client.Port = 25; //验证登陆 client.Credentials = new NetworkCredential("@@@@@@", "******");//@@@@@@是发件人邮箱地址,******是发件人邮箱密码 client.Send(mail); } catch (Exception ex) { Response.Write(ex.Message); } } }