/// <summary> /// SendTeamUpdates if required to all Citizens /// </summary> public static void SendTeamUpdates(string subject) { try { DataTable sourceTable = OperationsCRUD.ReadData(); if (sourceTable != null) { //Inform updates to each Citizen foreach (DataRow row in sourceTable.Rows) { string citizenEmail = Convert.ToString(row["CitizenEmail"]); Console.WriteLine(string.Format(" == Sending updates to Citizen: {0}", citizenEmail)); //For testing purpose //if (citizenEmail != "*****@*****.**") // continue; Utilities.SendTeamUpdatesMail(citizenEmail, subject); } } } catch (Exception ex) { Utilities.HandleException(ex); } }
public static bool SendMail(String emailAddress, String emailSubject, string emailBody) { string[] mailAccounts = { Credentials.MailO365UserName1, Credentials.MailO365UserName2 }; Random rand = new Random(); int index = rand.Next(mailAccounts.Length); string mailAccount = mailAccounts[index]; string mailAccountPassword = Credentials.MailO365Password; bool IsSuccess = false; var fromAddress = new MailAddress(mailAccount); var toAddress = new MailAddress(emailAddress); try { var smtp = new SmtpClient { Host = Credentials.MailO365Smtp, Port = Credentials.MailO365Port, EnableSsl = true, Credentials = new NetworkCredential(mailAccount, mailAccountPassword) }; using (MailMessage mail = new MailMessage()) { //Setting From , To and CC mail.From = new MailAddress(fromAddress.Address); mail.To.Add(new MailAddress(toAddress.Address)); mail.Subject = emailSubject; mail.Body = emailBody; mail.IsBodyHtml = true; smtp.Send(mail); IsSuccess = true; } } catch (Exception ex) { string message = ex.Message + ex.StackTrace; Console.WriteLine("VaccineForAll Exception: " + message); if (message.Contains("Syntax error in parameters or arguments. The server response was: 5.1.6 Recipient addresses in single label domains not accepted ")) { OperationsCRUD.DeleteMail(emailAddress); Console.WriteLine(String.Format(" = Deleted Invalid Email: {0}.", emailAddress)); } } return(IsSuccess); }
/// <summary> /// Lookup for available slots /// </summary> public void LookupAvailableSlots() { try { DataTable sourceTable = OperationsCRUD.ReadData(); if (sourceTable != null) { Console.WriteLine(string.Format("Total rows count: {0}", sourceTable.Rows.Count)); //Process for each Citizen foreach (DataRow row in sourceTable.Rows) { try { string district_id = Convert.ToString(row["CitizenDistrictID"]); string district_name = Convert.ToString(row["CitizenDistrictName"]); string citizenEmail = Convert.ToString(row["CitizenEmail"]); string citizenDoseChoice = Convert.ToString(row["CitizenDoseChoice"]); int citizenAge = Convert.ToInt32(row["CitizenAge"]); int citizenDailyMailSentCount = Convert.ToInt32(row["CitizenDailyMailSentCount"]); DateTime istDateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")); Console.WriteLine(string.Format(" == Processing data for citizenEmail:{0} - district_name:{1} - citizenAge:{2} - dose:{3}.", citizenEmail, district_name, citizenAge, citizenDoseChoice)); //For testing purpose //if (citizenEmail != "*****@*****.**") // continue; //Fetch data DataTable appoitmentData = LookupConsecutiveDays(district_id, citizenAge, citizenDoseChoice); if (appoitmentData.Rows.Count > 0) { Console.WriteLine(String.Format(" = Rows.Count:{0}.", appoitmentData.Rows.Count)); //Sort data DataView dataView = appoitmentData.DefaultView; dataView.Sort = "session_date asc"; DataTable sortedAppoitmentData = dataView.ToTable(); //Convert to Html table String html = Utilities.toHTML_Table(sortedAppoitmentData, citizenEmail, citizenAge, district_name, citizenDoseChoice); //Mail report bool IsSuccess = Utilities.SendMail(citizenEmail, "VaccineForAll Report", html); if (IsSuccess) { OperationsCRUD.UpdateMailCountSent(citizenEmail); } Console.WriteLine(String.Format(" = Report sent successfully.")); } //Marked Processed OperationsCRUD.MarkedProcessed(citizenEmail); } catch (Exception ex) { Utilities.HandleException(ex); } } } } catch (Exception ex) { Utilities.HandleException(ex); } }