public static async Task SendEmailDailyAppointmentToRM() { try { GenericMethods.Log(LogType.ActivityLog.ToString(), "DailyEmailService SendEmailDailyAppointmentToRM"); List <AppointmentDetail> appointListToday = new List <AppointmentDetail>(); appointListToday = await _context.AppointmentDetail.Where(p => p.AppointmentDateTime != null).ToListAsync(); appointListToday = appointListToday.Where(p => Convert.ToDateTime(p.AppointmentDateTime).Date == DateTime.Now.Date).ToList(); List <UserMaster> managerList = await _context.UserMaster.Where(p => p.Status == true && p.RoleId == (int)Roles.RelationshipManager).ToListAsync(); managerList = managerList.Where(p => appointListToday.Any(r => r.RelationshipManagerId == p.UserId)).ToList(); if (managerList.Count > 0) { foreach (var item in managerList) { var managerAppoints = appointListToday.Where(p => p.RelationshipManagerId == item.UserId).ToList(); var callDetail = _context.CallDetail.ToList().Where(p => managerAppoints.Any(r => r.CallId == p.CallId)); var callDetailView = (from call in callDetail join appoin in managerAppoints on call.CallId equals appoin.CallId select new { call.CallId, call.FirstName, call.LastName, call.MobileNumber, call.Address, AppointTime = appoin.AppointmentDateTime.Value.ToString("hh:mm tt"), CreatedByName = _context.UserMaster.ToList().FirstOrDefault(p => p.UserId == appoin.CreatedBy).FirstName, CreatedDate = appoin.CreatedDate.ToShortDateString(), appoin.Remarks }).ToList(); string FilePath = _hostingEnvironment.ContentRootPath + "//HTMLTemplate//DailyAppointRM.html"; //string FilePath = ConfigurationManager.AppSettings["HTMLPath"] + "//DailyAppointRM.html"; //string domainName = ConfigurationManager.AppSettings["DomainName"]; //string domainName = _configuration["TokenSettings:Client_URL"].ToString(); string domainName = _configuration.GetSection("Domains").GetSection("CurrentDomain").Value; StreamReader str = new StreamReader(FilePath); string MailText = str.ReadToEnd(); MailText = MailText.Replace("#MANAGER#", item.FirstName + " " + item.LastName); MailText = MailText.Replace("#DOMAINNAME#", domainName); string strHtmlTable = ""; StringBuilder sb = new StringBuilder(); //Table start. //sb.Append("<table cellpadding='5' cellspacing='0' style='border: 1px solid #ccc;font-size: 9pt;font-family:Arial'>"); sb.Append("<table style='border-color: #84b5e1; margin-left: auto; margin-right: auto;' width='100%' border='1'>"); sb.Append("<tbody>"); //Adding HeaderRow. sb.Append("<tr style='border-color: #84b5e1; background-color: #185f9e; text-align: center; color: #ffffff;'>"); //sb.Append("<th style='background-color: #B8DBFD;border: 1px solid #ccc'>" + "First Name" + "</th>"); sb.Append("<td><strong>#</strong></td>"); sb.Append("<td><strong>Client</strong></td>"); sb.Append("<td><strong>Appointment Time</strong></td>"); sb.Append("<td><strong>Mobile No.</strong></td>"); sb.Append("<td><strong>Address</strong></td>"); sb.Append("<td><strong>Remarks</strong></td>"); sb.Append("</tr>"); //Adding DataRow. int cnt = 1; foreach (var row in callDetailView) { if (cnt % 2 == 0) { sb.Append("<tr style='text-align: center; border-color: #84b5e1;'>"); } else { sb.Append("<tr style='text-align: center; border-color: #84b5e1; background-color: #c5ddf3;'>"); } sb.Append("<td>" + cnt + "</td>"); sb.Append("<td><a href='" + domainName + "/lead-followup/" + row.CallId + "'>" + row.FirstName + " " + row.LastName + "</a></td>"); sb.Append("<td>" + row.AppointTime + "</td>"); sb.Append("<td>" + row.MobileNumber + "</td>"); sb.Append("<td>" + row.Address + "</td>"); sb.Append("<td>" + row.Remarks + "</td>"); sb.Append("</tr>"); cnt++; } //Table end. sb.Append("</table>"); strHtmlTable = sb.ToString(); MailText = MailText.Replace("#APPOINTMENTSTABLE#", strHtmlTable); GenericMethods.Log(LogType.ActivityLog.ToString(), "Sending email to : " + item.Email); GenericMethods.SendEmailNotification(item.Email, "OmniCRM: Today's Appointments (" + DateTime.Now.ToString("dd-MMM-yyyy") + ")", MailText); } } } catch (Exception ex) { GenericMethods.Log(LogType.ErrorLog.ToString(), "SendEmailDailyAppointmentToRM: " + ex.ToString()); } }