Zoe
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <br /><br />
         接收者:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /><br />
        邮件标题:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /><br />
        邮件内容:<asp:TextBox ID="TextBox3" TextMode="MultiLine" runat="server"></asp:TextBox><br /><br />
        <asp:Button ID="Button1" runat="server" Text="发送" />
    </div>
    </form>
</body>
</html>
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)
    {
        string to = TextBox1.Text;
        string title = TextBox2.Text;
        string content = TextBox3.Text;

        //发送邮件
        //创建邮箱服务器对象
        SmtpClient smtp = new SmtpClient("smtp.qq.com");
        smtp.EnableSsl = true;
        smtp.UseDefaultCredentials = false;
        //发送者是谁
        MailAddress fr=new MailAddress("757113394@qq.com");
        //接收者是谁
        MailAddress t = new MailAddress(to);
        MailAddressCollection clist = new MailAddressCollection();
        clist.Add(t);
        //发送的邮件对象
        MailMessage mail = new MailMessage(fr,t);
       
        //给邮件对象标题属性赋值
        mail.Subject = title;
        //给邮件对象内容属性赋值
        mail.Body = content;
        //创建资格证书对象
        NetworkCredential cred = new NetworkCredential("757113394", "rykemipvuzbvbcbd");

        //设置资格证书
        smtp.Credentials = cred;
        //发送

        smtp.Send(mail);
    }

    
}

 

posted on 2017-06-12 13:53  口袋里的SKY  阅读(126)  评论(0编辑  收藏  举报