public void SendEmail(TicketMasterEmailMessage message) { try { MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(message.EmailFrom); foreach (var to in message.EmailTo) { mailMessage.To.Add(new MailAddress(to)); } if (!string.IsNullOrEmpty(message.AttachmentFilePath)) { mailMessage.Attachments.Add(new Attachment(message.AttachmentFilePath)); } mailMessage.Subject = message.Subject; mailMessage.IsBodyHtml = EmailType == EmailType.Html; mailMessage.Body = message.EmailMessage; _smtpServer.Credentials = new NetworkCredential(SmtpServerUsername, SmtpServerPassword); _smtpServer.Send(mailMessage); } catch (Exception e) { } }
public ActionResult ResetPassword(PasswordRequestViewModel model) { var user = _repositoryServices.GetUserByName(model.UserName); if (user == null) { ModelState.AddModelError("userNotExist", "User doesn't exist."); } if (ModelState.IsValid) { var aspNetUser = user.AspNetUser; var autoPassword = model.UserName + (new Random(DateTime.Now.Millisecond)).NextDouble(); UserManager.RemovePassword(user.ASPNetUserId); UserManager.AddPassword(user.ASPNetUserId, autoPassword); //Send Email var emailMessage = new TicketMasterEmailMessage(); emailMessage.EmailTo = new[] { user.Email }; emailMessage.EmailFrom = ConfigurationManager.AppSettings["BusinessEmail"]; emailMessage.Subject = "Request change of Password. Follow instructions in this email"; emailMessage.EmailMessage = string.Format("Click the link in this email and login using Username = {0} and Password={1}, to login. Please click on this http://entertainment.ticketmaster.co.uk to login and change your password using the credentials above. {2} Thanks from {3} Ticket Master Site", user.UserName, autoPassword, Environment.NewLine + Environment.NewLine, Environment.NewLine); _emailServices.SendEmail(emailMessage); return(View("EmailSentPasswordChangeRequest")); } return(View(model)); }
public ActionResult BookTeacherHelpTime(TeacherCalendarUpdateViewModel bookingTimeViewModel) { ViewBag.Message = "Book Teacher Time."; GetUIDropdownLists(); if (ModelState.IsValid) { if (bookingTimeViewModel.Delete != null) { var teacherCalendar = _teacherRepository.GetTeacherCalendarByBookingId(bookingTimeViewModel.CalendarBookingId); _teacherRepository.DeleteTeacherCalendarByBooking(teacherCalendar); return(View("_SuccessfullCreation")); } Teacher teacher = _teacherRepository.GetTeacherByName(User.Identity.Name); Student student = _teacherRepository.GetStudentByName(bookingTimeViewModel.StudentFullName); Subject subject = _teacherRepository.GetSubjectById(bookingTimeViewModel.SubjectId); foreach (var bookingTime in bookingTimeViewModel.BookingTimes) { _teacherRepository.SaveOrUpdateBooking(teacher, student, subject, new BookingTime { BookingTimeId = bookingTime.BookingTimeId, StartTime = DateTime.Parse(bookingTime.StartTime, new DateTimeFormatInfo { FullDateTimePattern = "yyyy-MM-dd HH:mm" }), EndTime = DateTime.Parse(bookingTime.EndTime, new DateTimeFormatInfo { FullDateTimePattern = "yyyy-MM-dd HH:mm" }) }, bookingTimeViewModel.Description); } var emailService = new EmailServices.EmailService(ConfigurationManager.AppSettings["smtpServer"], ConfigurationManager.AppSettings["smtpServerUser"], ConfigurationManager.AppSettings["smtpServerPassword"]); var emailMessage = new System.Net.Mail.MailMessage(); var fileInfo = new FileInfo(Server.MapPath("~/Infrastructure/EmailTemplates/TeacherBookingTime.html")); var html = fileInfo.OpenText().ReadToEnd(); html.Replace("{TeacherName}", teacher.EmailAddress); html.Replace("{StudentName}", student.EmailAddress); html.Replace("{SubjectName}", subject.SubjectName); html.Replace("{StartTime}", bookingTimeViewModel.BookingTimes[0].StartTime); html.Replace("{EndTime}", bookingTimeViewModel.BookingTimes[0].EndTime); emailService.EmailType = EmailType.Html; //emailService.SendEmail(new TicketMasterEmailMessage {EmailFrom= student.EmailAddress, EmailMessage = html,EmailTo = new List<string> {student.EmailAddress}, Subject = "Teacher Assistant's Booking Time Schedule"}); var message = new TicketMasterEmailMessage { EmailFrom = ConfigurationManager.AppSettings["BusinessEmail"], EmailTo = new List <string> { student.EmailAddress }, Subject = "Teacher Assistant's Booking Time Schedule", EmailMessage = html }; emailService.SendEmail(message); return(View("_SuccessfullCreation")); } return(View("BookTeacherHelpTime", bookingTimeViewModel)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); var ftpServerUser = ConfigurationManager.AppSettings["ftpServerUser"]; var ftpPassword = ConfigurationManager.AppSettings["ftpServerPassword"]; _emailService.SmtpServerUsername = ftpServerUser; _emailService.SmtpServerPassword = ftpPassword; var emailToList = _teacherRepository.GetAll().Select(p => p.EmailAddress).ToList(); var emailMessage = string.Format(@"Dear Teaching Staff, There has been a new Registrant: email Address: {0}. You may want to put them in their right roles at this stage, so that they can begin using the application for routine work. Many thanks MartinLayooInc Dev Team.", model.Email); var message = new TicketMasterEmailMessage { EmailFrom = ConfigurationManager.AppSettings["BusinessEmail"], EmailTo = emailToList, Subject = "New Student Registration", EmailMessage = emailMessage }; _emailService.SendEmail(message); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult EmailUsers(BulkEmailContentViewModel model) { try { if (ModelState.IsValid) { var attachemntPath = string.Empty; if (model.Attachment != null) { var attachment = model.Attachment; var binaryReader = new BinaryReader(attachment.InputStream); var fileBytes = binaryReader.ReadBytes(attachment.ContentLength); attachemntPath = Server.MapPath("/EmailAttachments/" + attachment.FileName); var fileInfo = new FileInfo(attachemntPath); var fileStream = fileInfo.Create(); fileStream.Write(fileBytes, 0, fileBytes.Length); fileStream.Close(); } var users = _repositoryAdminServices.GetAllUsers(); var to = new List <string>(); to.AddRange(users.Select(e => e.Email)); var mailMessage = new TicketMasterEmailMessage { AttachmentFilePath = attachemntPath, EmailFrom = System.Configuration.ConfigurationManager.AppSettings["BusinessEmail"], EmailTo = to, EmailMessage = model.EmailMessage, Subject = "Updates of Events and tickets coming soon" }; _emailService.SendEmail(mailMessage); return(View("Success")); } } catch (Exception e) { } return(View(model)); }
public void SendEmail(TicketMasterEmailMessage message) { MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(message.EmailFrom); foreach (var to in message.EmailTo) { mailMessage.To.Add(new MailAddress(to)); } if (!string.IsNullOrEmpty(message.AttachmentFilePath)) { mailMessage.Attachments.Add(new Attachment(message.AttachmentFilePath)); } mailMessage.Subject = message.Subject; mailMessage.Body = message.EmailMessage; _smtpServer.Credentials = new NetworkCredential("*****@*****.**", "eps1LonX!505First14Chars"); _smtpServer.Send(mailMessage); }
public bool ProcessIPNResults(HttpContext context, StreamWriter IPNWriter) { bool result = false; // *** Reload our invoice and try to match it // *** a real invoice int InvoiceNo = Int32.Parse(form["invoice"]); decimal amount = Convert.ToDecimal(form["mc_gross"]); clientEmail = null; int orderId = -1; var orderAmmount = new decimal(); var Username = string.Empty; var Password = string.Empty; //Get Client Order from DB: var booking = _bookingRepository.GetById(InvoiceNo); clientEmail = form["payer_email"]; if (!form["business"].Equals(System.Configuration.ConfigurationManager.AppSettings["BusinessEmail"])) { result = false; } if (booking.BookingId != InvoiceNo) { result = false; } orderAmmount = (decimal)(booking.NumberOfTickets * booking.Ticket.Price); if (orderAmmount != amount) { result = false; } // *** Send the response data back to PayPal for confirmation StringBuilder sbUrl = new StringBuilder(); sbUrl.Append("cmd=_notify-validate"); StringBuilder prodBuffer = new StringBuilder(); string username = null; string buyerEmail = null; foreach (string postKey in form) { sbUrl.Append("&" + postKey + "=" + form[postKey]); if (postKey.StartsWith("item_")) { prodBuffer.Append(form[postKey] + "_"); } if (postKey.StartsWith("buyer_email")) { buyerEmail = form[postKey]; } if (postKey.StartsWith("username")) { username = form[postKey]; } } string requestUriString = System.Configuration.ConfigurationManager.AppSettings["PaypalBaseUrl"]; this.httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(requestUriString); // Set values for the request back httpWebRequest.Method = "POST"; httpWebRequest.ContentType = "application/x-www-form-urlencoded"; httpWebRequest.Timeout = 10000; // *** Set properties //retrieve post string: byte[] lbPostBuffer = Encoding.GetEncoding(1252).GetBytes(sbUrl.ToString()); httpWebRequest.ContentLength = lbPostBuffer.Length; Stream loPostData = httpWebRequest.GetRequestStream(); loPostData.Write(lbPostBuffer, 0, lbPostBuffer.Length); loPostData.Close(); HttpWebResponse loWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); Encoding enc = Encoding.GetEncoding(1252); StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), enc); string verify = loResponseStream.ReadToEnd(); loWebResponse.Close(); loResponseStream.Close(); IPNWriter.WriteLine(DateTime.Now.ToString("dd/MM/yyyy") + ": " + verify); IPNWriter.Flush(); IPNWriter.Close(); if (verify.Contains("VERIFIED")) { booking.IsVerifiedPayment = true; _bookingRepository.Update(booking); //Send Confirmation Mail var emailPassword = System.Configuration.ConfigurationManager.AppSettings["emailPassword"]; var smtpUsername = System.Configuration.ConfigurationManager.AppSettings["BusinessEmail"]; var smtpClient = System.Configuration.ConfigurationManager.AppSettings["SmtpHostServer"]; //smtpClient.Credentials = new NetworkCredential {Password = emailPassword, UserName = smtpUsername }; var message = new TicketMasterEmailMessage { AttachmentFilePath = null, EmailFrom = smtpUsername, EmailMessage = string.Format( "This is confirmation that client {0} tickets will be dispatched as Paypal has verified transaction.", username), Subject = "Confirmation from Paypal payment gateway.", EmailTo = new List <string>() }; message.EmailTo.Add("*****@*****.**"); message.EmailTo.Add(smtpUsername); message.EmailTo.Add(clientEmail); var smtpServer = new EmailServices.EmailService(smtpClient); smtpServer.SendEmail(message); return(true); } return(false); }