public UserShows SendMessage(EmailMessage emailMessage) { UserShows us = null; try { // if entered show, send email saying entered show us = new UserShows(emailMessage.UserShowId); User user = new User(us.Userid); if (user.EmailAddress.Length < 5) { throw new Exception("NoEmai"); } var thisShow = new Shows(us.ShowID); var htmlContents = readTemplate("AdminEmailHandler", "html", thisShow, null); var plainContents = readTemplate("AdminEmailHandler", "txt", thisShow, null); htmlContents = htmlContents.Replace("[BODY]", emailMessage.body.Replace("\n", "<br>")); plainContents = plainContents.Replace("[BODY]", emailMessage.body); var mm = new MailMessage(); var htmlView = AlternateView.CreateAlternateViewFromString(htmlContents, null, MediaTypeNames.Text.Html); var plainView = AlternateView.CreateAlternateViewFromString(plainContents, null, MediaTypeNames.Text.Plain); mm.Body = plainContents; mm.AlternateViews.Add(htmlView); SmtpClient client = new SmtpClient(); mm.From = new MailAddress("*****@*****.**", "First Place Processing"); mm.To.Add(new MailAddress(user.EmailAddress, user.Name)); mm.Subject = emailMessage.Subject; client.Send(mm); us.ContactStatus = 1; us.ContactDate = DateTime.Now; us.SaveContactDetails(); } catch (Exception e) { AppException.LogEvent("SendMessage: " + e.Message + " " + e.StackTrace); } return us; }
public UserShows SendMessage(EmailMessage EmailMessage) { UserShows us = null; try { // if entered show, send email saying entered show us = new UserShows(EmailMessage.UserShowId); User user = new User(us.Userid); if (user.EmailAddress.Length < 5) { throw new Exception("NoEmai"); } Shows thisShow = new Shows(us.ShowID); String htmlContents = readTemplate("AdminEmailHandler", "html", thisShow, null); String plainContents = readTemplate("AdminEmailHandler", "txt", thisShow, null); htmlContents = htmlContents.Replace("[BODY]", EmailMessage.body.Replace("\n", "<br>")); plainContents = plainContents.Replace("[BODY]", EmailMessage.body); MailMessage mm = new MailMessage(); AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlContents, null, MediaTypeNames.Text.Html); LinkedResource logoImage = new LinkedResource(HttpContext.Current.Server.MapPath("~/Assets/logo.gif"), MediaTypeNames.Image.Gif); logoImage.ContentId = "LogoImage"; //htmlView.LinkedResources.Add(logoImage); AlternateView plainView = AlternateView.CreateAlternateViewFromString(plainContents, null, MediaTypeNames.Text.Plain); mm.Body = plainContents; mm.AlternateViews.Add(htmlView); SmtpClient client = new SmtpClient(); mm.From = new MailAddress("*****@*****.**", "First Place Processing"); mm.To.Add(new MailAddress(user.EmailAddress, user.Name)); mm.Subject = EmailMessage.Subject; client.Send(mm); us.ContactStatus = 1; us.ContactDate = DateTime.Now; us.SaveContactDetails(); } catch (Exception e) { AppException.LogEvent("SendMessage: "+ e.Message + " " + e.StackTrace); } return us; }
public JsonResult SendBulkEmailMessage(EmailMessage bulkEmailMessage) { StatusCls status = new StatusCls(); status.ClsID = bulkEmailMessage.UserShowId; UserShows us = new UserShows(bulkEmailMessage.UserShowId); User user = new User(us.Userid); if (user.EmailAddress.Length > 5) { Shows show = new Shows(us.ShowID); MailMessage mm = new MailMessage(); AlternateView plainView = AlternateView.CreateAlternateViewFromString(bulkEmailMessage.body, null, MediaTypeNames.Text.Plain); mm.Body = bulkEmailMessage.body; SmtpClient client = new SmtpClient(); mm.From = new MailAddress("*****@*****.**", "First Place Processing"); mm.To.Add(new MailAddress(user.EmailAddress, user.Name)); mm.Subject = bulkEmailMessage.Subject; client.Send(mm); us.ContactStatus = 1; us.ContactDate = DateTime.Now; us.SaveContactDetails(); status.Data = us.ContactDate.ToString("dd-MMM hh:mm:ss"); status.DogID = us.ContactStatus; } else { status.Status = 2; } return Json(new { status }); }
public JsonResult SendEMail(EmailMessage EmailMessage) { var mail = new EmailManager();; int status = 0; UserShows us = null; try { us = mail.SendMessage(EmailMessage); } catch (Exception e) { status = 1; if (e.Message == "NoEmail") { status = 2; } } return Json(new { Status = status, UserShowId = EmailMessage.UserShowId, ContactDate = (us != null ? us.ContactDate.ToString("dd-MMM hh:mm:ss") : ""), ContactStatus = (us != null ? us.ContactStatus : 0), }); }
public JsonResult SendBccEMail(EmailMessage EmailMessage) { var mail = new EmailManager(); int status = 0; try { mail.Send("*****@*****.**", new MailMessage { Subject = EmailMessage.Subject, Body = EmailMessage.body }); } catch (Exception e) { status = 1; if (e.Message == "NoEmail") { status = 2; } } return Json(new { Status = status, }); }