0
Answer

send email automatically in button click

scropio gurl

scropio gurl

10y
2.7k
1
previously i am trying to send mails in separate form like this enter image description here
but now i want to send mail automatically in respective email address..
Admin approve/reject documents now i want to add
when admin approve/reject any documents then respective document name and the value which admin select (like approve /reject ) send to his/her mail ... previously i send mail using sepearte form through code is
protected void btnSendMail_Click(object sender, EventArgs e) { string connStr = ConfigurationManager.ConnectionStrings["mydms"].ConnectionString
 SqlConnection mySQLconnection = new SqlConnection(connStr);
 string empId = string.Empty;
 DataTable dt = new DataTable();
 try
 {
 mySQLconnection.Open();
 for (int i = 0; i < Repeateremail.Items.Count; i++)
 {
 CheckBox checkboc =
((CheckBox)Repeateremail.Items[i].FindControl("chkSelect"));
 if (checkboc != null)
 {
 if (checkboc.Checked == true)
 {
 //get Current EMAIL_ID from the DataKey
 string emailId =
((Label)Repeateremail.Items[i].FindControl("lbl_email")).Text;
 //write code to send mail
 SendEmailUsingGmail(emailId);
 dt.Clear();
 dt.Dispose();
 }
 else if (checkboc.Checked == false)
 {
} } } } catch (Exception ex) { emailsent.Text="Failed"; } finally { empId = string.Empty; } }



  in above code i send mail through check-boxes when admin check on checkbox and then click on send mail then mail send but now i want when admin approve document then this respective document name and value send in his/her mail .
now i want to do this enter image description here


approve code is

protected void Button1_Click(object sender, EventArgs e)
  {         
 string connStr = ConfigurationManager.ConnectionStrings
["mydms"].ConnectionString;
 SqlConnection mySQLconnection = new SqlConnection(connStr);
 if (mySQLconnection.State == ConnectionState.Closed)
  {
mySQLconnection.Open();
 for (int i = 0; i < Repeater2.Items.Count; i++)
   {
   DropDownList DropDownListcontrol = ((DropDownList)Repeater2.Items[i].FindControl("DropDownList4"));
  Label DocId = ((Label)Repeater2.Items[i].FindControl("DocId"));
 SqlCommand cmd = new SqlCommand("approveddd", mySQLconnection);
  cmd.CommandType = CommandType.StoredProcedure;


 cmd.Parameters.Add("@DocID", SqlDbType.Int).Value = Convert.ToInt32((DocId.Text));

 cmd.Parameters.Add("@ApproveID", SqlDbType.Int).Value = Convert.ToInt32(DropDownListcontrol.SelectedValue);
   cmd.Parameters.Add("@ApproveBy", SqlDbType.VarChar, 50).Value = (Session["Login2"]);

 cmd.ExecuteNonQuery();
//UPDATE APPPROVEID IN DOCUMENTINFO TABLE
   //DMSLIB.Doc myDoc = new DMSLIB.Doc();
 ]//myDoc.MarkDocAs(Convert.ToInt16(DocId.Text), Convert.ToInt32(DropDownListcontrol.SelectedValue));
    }
 }
              else
              {
                  Supvisor.Text = "Error";
              }
              if (mySQLconnection.State == ConnectionState.Open)
              {
                  mySQLconnection.Close();
              }
                    }