private static void RunLateMatchResultCheckAndEmailResults() { WebRequest getUrl = WebRequest.Create(lateMatchResultUrl); Stream objStream = getUrl.GetResponse().GetResponseStream(); StreamReader objReader = new StreamReader(objStream); string response = objReader.ReadToEnd(); Email resultsEmail = new Email(false, lateMatchResultEmailAddress); resultsEmail.Send(lateMatchResultEmailSubject, response); }
// http://colinmackay.co.uk/blog/2011/05/02/custom-error-pages-and-error-handling-in-asp-net-mvc-3-2/ protected override void OnException(ExceptionContext filterContext) { try { ErrorService.Insert(new Error( filterContext.Exception.Message, filterContext.Exception.StackTrace, filterContext.HttpContext.User.Identity.Name)); ErrorService.Commit(); } catch (Exception ex) { // If the code ever reaches this point then I'm screwed // TODO Email here Email email = new Email(false, "*****@*****.**"); // Send email BEFORE user is saved. Otherwise you could reset their password to something unknown // No error handling. Same old story. Can't be arse at the moment email.Send("TBL Exception (Inner) - " + ex.Message, ex.StackTrace + "\n\n\n" + (ex.InnerException != null ? ex.InnerException.Message + "\n\n" + ex.InnerException.StackTrace : "No inner exception")); } Email email2 = new Email(false, "*****@*****.**"); // Send email BEFORE user is saved. Otherwise you could reset their password to something unknown // No error handling. Same old story. Can't be arse at the moment string subject = string.Format("TBL exception - {0}", filterContext.Exception.Message); var stacktrace = new StringBuilder(); Exception currentEx = filterContext.Exception; while(currentEx != null) { stacktrace.AppendLine(currentEx.Message); stacktrace.AppendLine(currentEx.StackTrace); stacktrace.AppendLine("--------------------"); currentEx = currentEx.InnerException; } email2.Send(subject, stacktrace.ToString()); //email2.Send("TBL Exception - " + filterContext.Exception.Message, filterContext.Exception.StackTrace + "\n\n\n" + (filterContext.Exception.InnerException != null ? filterContext.Exception.InnerException.Message + "\n\n" + filterContext.Exception.InnerException.StackTrace : "No inner exception")); // TODO Email? }
public ActionResult Index(ContactUsViewModel model) { List<string> emailAddresses = new List<string>(); string subject = string.Empty; if (ModelState.IsValid) { switch (model.Reason) { case ContactReason.AddPlayers: emailAddresses.Add(optionRepository.GetByName(Option.EXEC_EMAIL_REGISTRAR)); emailAddresses.Add(optionRepository.GetByName(Option.EXEC_EMAIL_WEBADMIN)); subject = this.GetSubject(model.Name, "needs to add some players"); break; case ContactReason.FoundBug: emailAddresses.Add(optionRepository.GetByName(Option.EXEC_EMAIL_WEBADMIN)); subject = this.GetSubject(model.Name, "has found a bug"); break; case ContactReason.NeedWebsiteHelp: emailAddresses.Add(optionRepository.GetByName(Option.EXEC_EMAIL_WEBADMIN)); subject = this.GetSubject(model.Name, "has a question"); break; case ContactReason.SomeOtherReason: emailAddresses.AddRange(GetExecEmailAddresses()); subject = this.GetSubject(model.Name, "has submitted some feedback"); break; } Email emailHandler = new Email(false); // Split and add email addresses foreach (string emailAddress in emailAddresses) emailHandler.AddToRecipient(emailAddress); try { emailHandler.Send(subject, model.Message, model.Email); return RedirectToAction("Sent"); } catch (EmailSendException) { TempData[FormMessages.MessageTypeFailure] = FormMessages.FeedbackSendError; } } return View(model); }
/// <exception cref="EmailSendException"></exception> public void ResetPassword(string username) { User user = membershipRepository.GetUserByUserName(username); // Don't dare if user doesn't exist if (user == null) return; // Don't really care how long the password is string randomPassword = Rand.String(8); user.Password = randomPassword.ToMd5(); Email email = new Email(false, user.Email); // Send email BEFORE user is saved. Otherwise you could reset their password to something unknown // No error handling. Same old story. Can't be arse at the moment email.Send("TBL password reset", "Hello " + user.UserName + "\n\nYour new password is: " + randomPassword + ""); SaveUser(user); }