瀚城老爷子

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
body>
    <form id="form1" runat="server">
    <div>

        发送至:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        标题:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        内容:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="发送" />

    </div>
    </form>
</body>
前台
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Click += Button1_Click;

    }

    void Button1_Click(object sender, EventArgs e)
    {


        //创建发送邮件的客户端对象
        SmtpClient sp = new SmtpClient("smtp.sina.com");//使用新浪
        //创建发送者、接收者对象
        MailAddress from = new MailAddress("lzx920627@sina.com");
        MailAddress to = new MailAddress(TextBox1.Text.Trim());
        //创建发送对象
        MailMessage mess = new MailMessage(from, to);
        //创建发送标题
        mess.Subject = TextBox2.Text;
        //创建发送内容
        mess.Body = TextBox3.Text;
        //创建验证信息
        NetworkCredential cre = new NetworkCredential("lzx920627@sina.com", "Lzx0627@!!!");
        //客户端证书设置
        sp.Credentials = cre;
        //发送
        sp.Send(mess);
    }
}
后台

 

posted on 2017-06-28 08:43  瀚城老爷子  阅读(110)  评论(0编辑  收藏  举报