Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i send mail successfully but i want the in email like this docname : abc status= approve

i have a drop down in table like this
http://i.stack.imgur.com/9tGh7.png[^]

now here i want when admin click submit button then docname (like plan method ) and dropdown value which admin select (like approve/rejct/pending) for e.g he select reject then when user receive mail he will be able to see like this

docname : plan method status : reject

here is code in button

C#
protected void Button1_Click(object sender, EventArgs e)
    {

            string connStr = 
             ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
          SqlConnection mySQLconnection = new SqlConnection(connStr);
          string empId = string.Empty;
          DataTable dt = new DataTable();

          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"]);




                  string DocName = 
          ((Label)Repeater2.Items[i].FindControl("DocName")).Text;
                  string emailId = 
               ((Label)Repeater2.Items[i].FindControl("YourEamil")).Text;
                  DropDownList dropdownvalue = 
               ((DropDownList)Repeater2.Items[i].FindControl("DropDownList4"));

                  string docname = String.Empty;
                  string emailID = String.Empty;
                  string dropdownvalues = String.Empty;

                  if (DocName.ToString() != "")
                  {
                      docname = DocName.ToString();
                  }
                  else
                  {
                      docname = "Unavailable";
                  }
                     if (emailId.ToString() != "")
                  {
                      emailID = emailId.ToString();
                  }
                  else
                  {
                      emailID = "Unavailable";
                  }

                  if (dropdownvalue.SelectedItem.ToString() != "")
                  {
                      dropdownvalues = dropdownvalue.SelectedItem.ToString();
                  }
                  else
                  {
                      dropdownvalues = "Unavailable";
                  }


                  SendEmailUsingGmail(DocName.ToString(), emailId.ToString(), 
           dropdownvalue.ToString());


                  cmd.ExecuteNonQuery();



              }

          }
          else
          {
              Supvisor.Text = "Error";
          }
          if (mySQLconnection.State == ConnectionState.Open)
          {
              mySQLconnection.Close();
          }

                }
    private void SendEmailUsingGmail(string DocName, string emailId, string
     dropdownvalue)
    {
        try
        {
            SmtpClient smtp = new SmtpClient();
            smtp.Credentials = new NetworkCredential("johkett@gmail.com", "123123120");
            smtp.Port = 587;
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            MailMessage message = new MailMessage();
            message.From = new MailAddress("johkett@gmail.com");
            message.To.Add(emailId);

            message.Subject = "DropDownList4 " + dropdownvalue;
            message.Body = "DocName=" + DocName + " DropDownList4=" + dropdownvalue;
            //message.Subject = "Write your email subject here";
            //message.Body = "write the content of the email here";
            smtp.Send(message);
        }
        catch (Exception ex)
        {
            Response.Write("Error occured: " + ex.Message.ToString());
        }
    }


like this i want to see in email

http://i.stack.imgur.com/IlgLG.png[^]

how i done this
Posted
Updated 24-Nov-13 4:14am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900