Send confirmation Email after Approve request using C# and VB.Net in ASP.Net

Last Reply 10 months ago By pandeyism

Posted 10 months ago

Hey,

In below code i want to send email to the user after approving and rejecting the request of the user by admin.

so please help me.

namespace ait0207_sem7_
{
    public partial class WebForm7 : System.Web.UI.Page
    {
        protected void btn_approve_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Mycon"].ToString());
       
            foreach (GridViewRow row in Gv_approve.Rows)
            {
                CheckBox status = (row.Cells[3].FindControl("CheckBox1") as CheckBox);

                if (status.Checked)
                {
                    try
                    {
                        SqlCommand cmd = new SqlCommand("Update registration set status=1 where email= + '" + row.Cells[1].Text + "'", con);
                        cmd.CommandType = CommandType.Text;

                        cmd.Connection = con;

                        con.Open();
                        int suc = cmd.ExecuteNonQuery();
                        SqlDataReader dar = cmd.ExecuteReader();

                        if (suc > 0)
                        {
                            SendMail(row.Cells[1].Text);
                            Gv_approve.DataBind();
                            if (Gv_approve.Rows.Count == 0)
                            {
                                lbl_app.CssClass = "text-center text-primary";
                                lbl_app.Text = "All Users are approved ";
                                btn_approve.Visible = false;
                            }
                        }
                    }
                    catch
                    {                        

                    }
                    finally
                    {
                        if (con.State == ConnectionState.Open)
                            con.Close();
                    }
                }
            }
            lbl_app.CssClass = "text-center text-success";
            Response.Redirect("MIS_admin.aspx");
            lbl_app.Text = "Status Updated Successfully";
        }

        private void SendMail(string text)
        {
            throw new NotImplementedException();
        }

        protected void btn_rjct_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Mycon"].ToString());
            foreach (GridViewRow row in Gv_approve.Rows)
            {
                CheckBox status = (row.Cells[3].FindControl("CheckBox1") as CheckBox);

                if (status.Checked)
                {
                    try
                    {
                        SqlCommand cmd = new SqlCommand("delete from registration  where email= + '" + row.Cells[1].Text + "'", con);
                        cmd.CommandType = CommandType.Text;

                        cmd.Connection = con;

                        con.Open();
                        int suc = cmd.ExecuteNonQuery();

                        if (suc > 0)
                        {
                            SendMail(row.Cells[0].Text);
                            Gv_approve.DataBind();
                            if (Gv_approve.Rows.Count == 0)
                            {
                                lbl_app.CssClass = "text-center text-primary";
                                lbl_app.Text = "All Users are rejected ";
                                btn_approve.Visible = false;
                            }
                        }
                    }
                    catch
                    {                      
                    }
                    finally
                    {
                        if (con.State == ConnectionState.Open)
                            con.Close();
                    }
                }
            }
            lbl_app.CssClass = "text-center text-success";
            
            lbl_app.Text = "Status Updated Successfully";
        }
    }
}

 

 

 

This question does not have replies that have been liked.