public void doWork(object sender) { try { Email emailObj = new Email(); string path;//= @"D:"; path = @"E:\EmailWindowsService\XmlDataFiles\"; DataSet dsEmailT = new DataSet(); DataSet dsSheDuleT = new DataSet(); DataSet dsSmtp = new DataSet(); DataSet dsUsers = new DataSet(); dsEmailT.ReadXml(path + "EmailTemplates.xml"); dsSheDuleT.ReadXml(path + "sheduleTemplate.xml"); dsSmtp.ReadXml(path + "SmtpSettings.xml"); int m = 0; foreach (DataRow dr in dsSheDuleT.Tables[0].Rows) { #region SheduleForLoop if (dr["EmailTemplateName"].ToString() == null || dr["EmailTemplateName"].ToString().Trim() == "0" || dr["EmailTemplateName"].ToString().Trim() == "") m++; else { if (((Convert.ToDateTime(DateTime.Now.ToString())).CompareTo(Convert.ToDateTime(dr["SheduleTime"].ToString())) != -1)) { if (dr["Status"].ToString() != "Send" || dr["Status"].ToString().Contains("pending")) { DataRow[] emailT = dsEmailT.Tables[0].Select("id=" + dr["EmailTemplateName"].ToString().Trim()); emailObj.UserName = emailT[0]["UserName"].ToString(); emailObj.Password = emailT[0]["Password"].ToString(); emailObj.Port = Convert.ToInt32(dsSmtp.Tables[0].Rows[0]["PortNo"]); emailObj.HostName = dsSmtp.Tables[0].Rows[0]["Host"].ToString(); emailObj.FromAddress = emailT[0]["FromAddress"].ToString(); emailObj.Subject = emailT[0]["Subject"].ToString(); emailObj.Body = emailT[0]["Body"].ToString(); dsUsers.ReadXml(path + "users.xml"); #region userForLoop int i = 0; foreach (DataRow user in dsUsers.Tables[0].Rows) { i++; dsUsers.WriteXml("E:\\userS.xml"); if (user["UserId"].ToString() == null || user["UserId"].ToString().Trim() == "0" || user["UserId"].ToString() == "") i++; else { if (Convert.ToBoolean(user["isActive"])) emailObj.ToAddresses.Add(new MailAddress(user["EmailId"].ToString())); } } #endregion emailObj.sendEmail(true); dr["Status"] = "Send"; //ADDSEmailServiceEvents("mail Send "); } } } dsSheDuleT.WriteXml(path + "sheduleTemplate.xml"); } #endregion } catch (Exception ex) { //string local_strMsg = "Problem in service at starting stage"; //ADDSEmailServiceEvents("exception: " + ex.Message); } }