i am trying to send mail through check boxes and i done it but here i want when admin click on check boxes and press on button then admin get the value of document name and status from repeater and then send mail to user
like when admin send mail in any email id then it show like this when user receive mail document name: abc status: reject
DocID DocName Uplaodedfile UserEmail DocType DepType status
1 ABC def.pdf abcdef@gmail.com pdf hr reject
2 hr hrdoc.pdf johkety@gmail.com pdf hr approve
this is email button code
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;
string DocName = ((Label)Repeateremail.Items[i].FindControl("DocName")).Text;
string Status = ((Label)Repeateremail.Items[i].FindControl("Status")).Text;
//write code to send mail
SendEmailUsingGmail(emailId,DocName,Status);
dt.Clear();
dt.Dispose();
}
else if (checkboc.Checked == false)
{
}
}
}
}
catch (Exception ex)
{
emailsent.Text="Failed";
}
finally
{
empId = string.Empty;
}
}
private void SendEmailUsingGmail(string toEmailAddress,string DocName,string Status)
{
try
{
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new NetworkCredential("johmm@gmail.com", "12234");
smtp.Port = 587;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
MailMessage message = new MailMessage();
message.From = new MailAddress("johmm@gmail.com");
message.To.Add(toEmailAddress);
message.To.Add(DocName);
message.To.Add(Status);
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());
}
}
but it shows me error
in this line
catch (Exception ex)
{
emailsent.Text="Failed";
}
`Error: Object reference not set to an instance of an object