public static void SendEmails() { List <UserEmailData> userEmailDataList = GetEmailAlertEnabledUsers(); logger.Info($"Email alert enabled users count: {userEmailDataList.Count}"); if (userEmailDataList.Count == 0) { return; } foreach (UserEmailData userEmailData in userEmailDataList) { DateTime currentPayPeriodStartDate = Forecast.GetCurrentPayPeriodStartDate(userEmailData.Start_Date_Even_Ww); int daysBeforeEndDate = (currentPayPeriodStartDate.AddDays(13) - DateTime.Today).Days; if (daysBeforeEndDate != userEmailData.Email_Alert_Days_Before) { continue; } VacationData vacationData = GetVacationData( userEmailData.Id, currentPayPeriodStartDate, currentPayPeriodStartDate.AddDays(13)); if (vacationData == null || vacationData.Take == 0) { continue; } EmailSender.SendEmail( userEmailData.Email, "Reminder to take vacation", $@"Hello {userEmailData.Email}!<br><br> According to our records, you're due to take <span style=""font-size: 2em;"">{vacationData.Take}</span> hours of vacation during the current pay period, {currentPayPeriodStartDate.ToString("yyyy-MM-dd")} to {currentPayPeriodStartDate.AddDays(13).ToString("yyyy-MM-dd")}.<br><br>" + @"Please <a href='https://vacation-accrual-buddy.azurewebsites.net/Home/Preferences' target='_blank'>click here</a> to update your email alert preferences.<br><br> If you have any additional questions, please contact Vacation Accrual Buddy at <a href='mailto:[email protected]' target='_blank'>[email protected]</a>." ); string message = $"Sent reminder email to {userEmailData.Email}"; Console.WriteLine(message); logger.Info(message); } }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("No arguments were passed"); Environment.Exit(0); } IConfigurationRoot Configuration = new ConfigurationBuilder() .AddUserSecrets <Program>().Build(); _connStr = Configuration["ConnectionString"]; Smtp_Host = Configuration["Smtp_Host"]; Smtp_Port = Convert.ToInt32(Configuration["Smtp_Port"]); Smtp_Username = Configuration["Smtp_Username"]; Smtp_Password = Configuration["Smtp_Password"]; switch (args[0].ToLower()) { case "forecastvacationdata": { Forecast.ForecastVacationData(); break; } case "sendreminderemails": { Email.SendEmails(); break; } default: { string message = $"Invalid arguments were passed: {args[0]}"; Console.WriteLine(message); logger.Error(message); break; } } }