zoukankan      html  css  js  c++  java
  • 发送邮件

    1.制作客户端邮件发送系统(winform版)

    前台:



    后台


            private void button1_Click(object sender, EventArgs e)
            {
                MailMessage msg = new MailMessage();
                msg.Subject = this.textBox2.Text;
                msg.Body = this.textBox3.Text;


                msg.From = new MailAddress("1059625015@qq.com");
                msg.To.Add(textBox1.Text);
                msg.IsBodyHtml = true;


                SmtpClient client = new SmtpClient();
                client.Host = "smtp.qq.com"; //发件方服务器地止
                client.Port = 25;  //发件方端口


                NetworkCredential credential = new NetworkCredential();
                credential.UserName = "1059625015";
                credential.Password = "57483985shang146";


                client.Credentials = credential;  //把证书交给代理


                Attachment att = new Attachment(this.textBox4.Text);
                msg.Attachments.Add(att);
                client.Send(msg);
            }


            private void button2_Click(object sender, EventArgs e)
            {
                if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    this.textBox4.Text = this.openFileDialog1.FileName;
                }
            }




    2.实现用户注册时,向其油箱发送激活码邮件,并进行状态处理。




    login前台:


     <div>
           
            <table style="100%;">
                <tr>
                    <td>
                        用户名:</td>
                    <td>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        密码:</td>
                    <td>
                        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        Email:</td>
                    <td>
                        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="注册" />
                    </td>
                    <td>
                        &nbsp;</td>
                </tr>
            </table>


        </div>


    login后台:


            protected void Button1_Click(object sender, EventArgs e)
            {
                string userName = TextBox1.Text.Trim();
                string pwd = TextBox2.Text.Trim();
                string email = TextBox3.Text.Trim();
                string activeCode = Guid.NewGuid().ToString().Substring(0,6);


                string conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
                SqlConnection conn = new SqlConnection(conStr);
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "insert into  T_Eamil (FUserName,FPassword,FEmail,FActive,FActiveCode) values 


    (@name,@pwd,@email,@active,@activeCode) select @@IDENTITY";
                cmd.Parameters.Add(new SqlParameter("name", userName));
                cmd.Parameters.Add(new SqlParameter("pwd",pwd));
                cmd.Parameters.Add(new SqlParameter("email", email));
                cmd.Parameters.Add(new SqlParameter("active", false));
                cmd.Parameters.Add(new SqlParameter("activeCode", activeCode));
                int num=Convert.ToInt32(cmd.ExecuteScalar());
                sendMail(email, activeCode, num);


                Response.Redirect("loginMessage.aspx");
                conn.Close();
                conn.Dispose();
                
            }


            protected void sendMail(string email,string activeCode,int id)
            {
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress("1059625015@qq.com");
                msg.To.Add(email);
                msg.Subject = "请激活注册";


                StringBuilder contentBuilder = new StringBuilder();
                contentBuilder.Append("请单击以下连接完成激活!");
                contentBuilder.Append("<a href='http://localhost:2533/index.aspx?id=" + id.ToString() + "&activeCode=" 


    + activeCode + "'>激活</a>");
                msg.Body = contentBuilder.ToString();
                msg.IsBodyHtml = true;


                SmtpClient client = new SmtpClient();
                client.Host = "smtp.qq.com";
                client.Port = 25;


                NetworkCredential credential = new NetworkCredential();
                credential.UserName = "1059625015";
                credential.Password = "57483985shang146";


                client.Credentials = credential;
                client.Send(msg);
            }


    loginMessage前台


    <div>
         恭喜您注册成功。。。。。。。。。。。。。
        </div>


    index后台


     protected void Page_Load(object sender, EventArgs e)
            {
                int id = Convert.ToInt32(Request["id"]);
                string activeCode = Request["activeCode"].ToString();
                int num = 0;
                string conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
                SqlConnection conn = new SqlConnection(conStr);
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "select * from T_Eamil where Id=@id";
                cmd.Parameters.Add(new SqlParameter("id",id));
                SqlDataReader read=cmd.ExecuteReader();
                if (read.Read())
                {
                    if (read.GetString(read.GetOrdinal("FActiveCode")) == activeCode)
                    {
                        num = 1;
                    }
                    else
                    {
                        num = 0;
                        Response.Write("验证码不正确");
                    }
                }
                else
                {
                    Response.Write("用户不存在!!");
                }
                
                   
             
                conn.Close();
                conn.Dispose();


                if (num == 1)
                {
                    SqlConnection conn1 = new SqlConnection(conStr);
                    conn1.Open();
                    SqlCommand cmd1 = conn1.CreateCommand();
                    cmd1.CommandText = "update T_Eamil set FActive='True' where Id=@id1";
                    cmd1.Parameters.Add(new SqlParameter("id1", id));
                    cmd1.ExecuteNonQuery();
                    conn1.Close();
                    conn1.Dispose();
                }
            }

  • 相关阅读:
    hdu1418 欧拉公式
    hdu1215七夕节 筛选法求公因子和
    hdu1215 The area
    hdu1005Number Sequence
    hdu1021 数学题 并不是说难,而是数学题那种简单朴素的思想get不到
    Mongo第三个参数的用法
    js 显示刚刚上传的图片 (onchange事件)
    在linux中安装memcache服务器
    jQuery 倒计时
    PHP获取文章发布时间
  • 原文地址:https://www.cnblogs.com/qiqiBoKe/p/2844755.html
Copyright © 2011-2022 走看看