Exemplo n.º 1
0
        public bool SendMail(User user, Mailing mail, Price price, MidiFile file)
        {
            if (user.Email == null)
                return false;

            if (price != null)
            {
                if (UpdatePromotionalPricing(user, price) == false)
                    return false;
            }

            try
            {
                SmtpClient client = new SmtpClient("m02.internetmailserver.net", 587);
                client.EnableSsl = false;
                MailAddress from = new MailAddress("*****@*****.**", "PianoCrumbs.com");
                MailAddress to = new MailAddress(user.Email, "");
                MailMessage message = new MailMessage(from, to);
                message.Subject = mail.Subject;
                message.IsBodyHtml = true;

                string fileName = "";
                string urlAction = "";

                if (file != null)
                {
                    fileName = file.Name;
                    urlAction = Url.Action("MidiView", "Crumbs", new { id = file.MidiID, name = file.DisplayName }, "http");
                }

                string latestLinks = "";
                IQueryable<MidiFile> latestFiles = crumbsRepository.LatestCrumbs.Take(5);
                foreach (var item in latestFiles)
                {
                    string url = Url.Action("MidiView", "Crumbs", new { id = item.MidiID, name = item.DisplayName }, "http");
                    latestLinks += string.Format("<p><a href='{0}'>{0}</a></p>", url);
                }

                string popualrLinks = "";
                IQueryable<MidiFile> popularFiles = crumbsRepository.RatedCrumbs.Take(5);
                foreach (var item in popularFiles)
                {
                    string url = Url.Action("MidiView", "Crumbs", new { id = item.MidiID, name = item.DisplayName }, "http");
                    popualrLinks += string.Format("<p><a href='{0}'>{0}</a></p>", url);
                }

                message.Body = string.Format(mail.Text, user.UserName, fileName, urlAction, latestLinks, popualrLinks);

                string unsubLink = Url.Action("Unsubscribe", "Account", new { username = user.UserName, reset = CrumbsExtensions.HashResetParams(user.UserName, user.UserKey) }, Request.Url.Scheme);
                message.Body += "<p><a href='" + unsubLink + "'>Unsubscribe</a>";

                NetworkCredential myCreds = new NetworkCredential("*****@*****.**", "Crumbs123", "");
                client.Credentials = myCreds;

                client.Send(message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception is:" + ex.ToString());
                return false;
            }

            SentMail sent = new SentMail();
            sent.UserID = user.UserID;
            sent.MailID = mail.ID;
            sent.Date = DateTime.Now;

            crumbsRepository.InsertOrUpdateSentMail(sent);
            crumbsRepository.Save();

            return true;
        }
Exemplo n.º 2
0
        public ActionResult CreateMailing(Mailing crumbsmodel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    crumbsRepository.InsertOrUpdateMailing(crumbsmodel);
                    crumbsRepository.Save();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception is:" + ex.ToString());
                }

                return RedirectToAction("MassMail");
            }

            return View(crumbsmodel);
        }
Exemplo n.º 3
0
 public ActionResult EditMailing(Mailing crumbsmodel)
 {
     if (ModelState.IsValid && crumbsmodel.ID > 0)
     {
         crumbsRepository.InsertOrUpdateMailing(crumbsmodel);
         crumbsRepository.Save();
         return RedirectToAction("MassMail");
     }
     return View(crumbsmodel);
 }
Exemplo n.º 4
0
 public ActionResult CreateMailing()
 {
     Mailing crumbsmodel = new Mailing();
     return View(crumbsmodel);
 }