Ejemplo n.º 1
0
        private IActionResult EditTemplateSend(string id, bool all)
        {
            id = (id ?? string.Empty).Trim();
            if (id.Length == 0)
            {
                return(NotFound());
            }
            string   listName = MailTemplate.GetListName(id);
            MailList list;

            using (MailDemonDatabase db = dbProvider.GetDatabase())
            {
                list = db.Lists.FirstOrDefault(l => l.Name == listName);
            }
            if (list == null)
            {
                return(NotFound());
            }
            if (bulkMailSender == null)
            {
                return(NotFound());
            }
            string unsubscribeUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}/{nameof(Unsubscribe)}/{id}?token={{0}}";

            bulkMailSender.SendBulkMail(list, mailCreator, mailSender, GetViewBagForTemplate(), all, id, unsubscribeUrl).ConfigureAwait(false).GetAwaiter();
            TempData["Message"] = Resources.SendStarted;
            return(RedirectToAction(nameof(HomeController.EditTemplate), new { id }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DebugTemplate(string id)
        {
            if (HttpContext.Request.Method == "POST")
            {
                // switch to GET request, to avoid stupid double form post popup
                return(RedirectToAction(nameof(DebugTemplate), new { id }));
            }

            id = (id ?? string.Empty).Trim();
            if (id.Length == 0)
            {
                return(NotFound());
            }
            string   listName = MailTemplate.GetListName(id);
            MailList list;

            using (MailDemonDatabase db = dbProvider.GetDatabase())
            {
                list = db.Lists.FirstOrDefault(l => l.Name == listName);
            }
            if (list == null)
            {
                return(NotFound());
            }

            string unsubscribeToken      = Guid.NewGuid().ToString("N");
            MailListSubscription tempReg = new MailListSubscription
            {
                EmailAddress     = "*****@*****.**",
                IPAddress        = HttpContext.GetRemoteIPAddress().ToString(),
                FirstName        = "Bob",
                LastName         = "Smith",
                Company          = "Fake Company",
                ListName         = list.Name,
                SubscribedDate   = DateTime.UtcNow,
                SubscribeToken   = Guid.NewGuid().ToString("N"),
                Expires          = DateTime.MinValue,
                MailList         = list,
                UnsubscribeToken = unsubscribeToken,
                UnsubscribeUrl   = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}/{nameof(Unsubscribe)}/{list.Name}?token={unsubscribeToken}"
            };
            MimeMessage msg = await mailCreator.CreateMailAsync(id, tempReg, GetViewBagForTemplate(), (_html, subject) =>
            {
                return(_html.Replace("<body>", "<body><div style='padding: 10px; width: 100%; background-color: #2A2A2A; border-bottom: 1px solid #444444;'>SUBJECT: " + System.Web.HttpUtility.HtmlEncode(subject) + "</div>"));
            });

            string html = msg.HtmlBody;

            return(Content(msg.HtmlBody, "text/html"));
        }