예제 #1
0
        private void SendEmailMessage(Reminder reminder, Profile profile, Contact contact)
        {
            string fromEmailAddress = profile.EmailAddress;
            string toEmailAddress   = contact.EmailAddress;
            string emailSubject     = string.Format("Reminder from {0} {1} - {2}", profile.FirstName, profile.LastName, DateTime.Now.ToString());
            string emailBody        = this.EmailMessageToSend(reminder, profile, contact);
            var    emailMessage     = new MessageEmail();

            emailMessage.Send(fromEmailAddress, toEmailAddress, emailSubject, emailBody);
        }
예제 #2
0
//		public JsonResult Send()
//		{
//			var contactList = new List<SelectListItem>();
//			DateTime currentDateTime;
//			try
//			{
//				var reminders = new ReminderDb().Reminders;

//				foreach (var reminder in reminders)
//				{
//					TimeSpan timeDifference;

//					var contact = new ReminderDb().Contacts.Where(c => c.Id == reminder.ContactId).FirstOrDefault();

//					int prodServerTimeDifference = 0;

//					switch (contact.TimeZone)
//					{
//						case "PST": prodServerTimeDifference = Convert.ToInt32(ConfigurationManager.AppSettings["PSTOffSetHours"]); break;
//						case "MST": prodServerTimeDifference = Convert.ToInt32(ConfigurationManager.AppSettings["MSTOffSetHours"]); break;
//						case "CST": prodServerTimeDifference = Convert.ToInt32(ConfigurationManager.AppSettings["CSTOffSetHours"]); break;
//						case "EST": prodServerTimeDifference = Convert.ToInt32(ConfigurationManager.AppSettings["ESTOffSetHours"]); break;
//					}

//#if DEBUG
//					currentDateTime = DateTime.Now;
//#else
//					currentDateTime = DateTime.Now.AddHours(prodServerTimeDifference);
//#endif

//					timeDifference = reminder.ReminderDateTime - currentDateTime;
//					int RemdinerMinutes = Convert.ToInt32(ConfigurationManager.AppSettings["RemdinerMinutes"]);


//					if (timeDifference.Seconds > 0 && timeDifference.Minutes <= RemdinerMinutes && reminder.ReminderDateTime.Date.Equals(currentDateTime.Date) && !reminder.Sent)
//					{

//						var profile = _db.Profiles.ToList().Find(p => p.Id == contact.ProfileId);
//						if (contact.Active && !profile.DeActivate)
//						{
//							bool reminderSent = false;
//							if (contact.SendEmail)
//							{
//								SendEmail(reminder, profile, contact);

//								contactList.Add(new SelectListItem()
//													{
//															Text = string.Format("{0} {1}", contact.FirstName.Trim(), contact.LastName.Trim()),
//															Value = reminder.Message

//													});
//								reminderSent = true;

//								var reminderHistory = new ReminderHistory();
//								reminderHistory.ContactId = contact.Id;
//								reminderHistory.Message = reminder.Message;
//								reminderHistory.ProfileId = profile.Id;
//								reminderHistory.ReminderDateTime = reminder.ReminderDateTime;
//								reminderHistory.ReminderId = reminder.Id;
//								reminderHistory.EmailSent = true;
//								reminderHistory.SMSSent = false;
//								reminderHistory.MessageSentDateTime = currentDateTime;
//								_db.ReminderHistories.Add(reminderHistory);
//								_db.Save();
//							}

//							if (contact.SendSMS)
//							{
//								SendSMS(reminder, profile, contact);

//								contactList.Add(new SelectListItem()
//								{
//									Text = string.Format("{0} {1}", contact.FirstName.Trim(), contact.LastName.Trim()),
//									Value = contact.Id.ToString().Trim()
//								});

//								reminderSent = true;

//								var reminderHistory = new ReminderHistory();
//								reminderHistory.ContactId = contact.Id;
//								reminderHistory.Message = reminder.Message;
//								reminderHistory.ProfileId = profile.Id;
//								reminderHistory.ReminderDateTime = reminder.ReminderDateTime;
//								reminderHistory.ReminderId = reminder.Id;
//								reminderHistory.EmailSent = false;
//								reminderHistory.SMSSent = true;
//								reminderHistory.MessageSentDateTime = currentDateTime;
//								_db.ReminderHistories.Add(reminderHistory);
//								_db.Save();
//							}

//							if (reminderSent)
//							{
//								_db.Reminders.ToList().Find(r => r.Id == reminder.Id).Sent = true;
//								_db.Save();
//							}

//						}
//					}

//				}

//			}
//			catch (Exception exception)
//			{
//				contactList.Add(new SelectListItem(){Selected = false, Text = exception.Message, Value = exception.InnerException.ToString()});
//			}

//			if (contactList.Count == 0)
//			{
//				contactList.Add(new SelectListItem(){Selected = false, Text = "No appointments to send out", Value = "none"});
//			}

//			return Json(contactList, JsonRequestBehavior.AllowGet);
//		}

        public void SendEmail(Reminder reminder, Profile profile, Contact contact)
        {
            string fromEmailAddress = profile.EmailAddress;
            string toEmailAddress   = contact.EmailAddress;
            string emailSubject     = string.Format("Reminder from {0} {1} - {2}", profile.FirstName, profile.LastName, DateTime.Now.ToString());
            string emailBody        = string.Format("Hi {0}, <br/> This is a reminder for you to {1} at {2}. <br/> Sincerely,<br/> {3}", contact.FirstName.Trim(), reminder.Message, reminder.ReminderDateTime.DayOfWeek + " " + reminder.ReminderDateTime.ToString(), profile.FirstName);

            var emailMessage = new MessageEmail();

            emailMessage.Send(fromEmailAddress, toEmailAddress, emailSubject, emailBody);
        }