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()); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)