public ActionResult Send(MailingModel model)
        {
            if (AuthContext.CurrentContext.CurrentUser == null)
                return View("Login");

            if (!ModelState.IsValid)
                return View("Index", model);

            var recipients = new List<Recipient>();

            if (model.To == "base" || model.To == "todos")
                using (var session = PersistenceHelper.OpenSession())
                    recipients = new RecipientRepository(session).GetActive().ToList();
            else
                model.To.Replace(",", ";").Replace(" ", "").Split(';').ToList().ForEach(
                        r => recipients.Add(new Recipient {IsActive = true, Email = r, Name = r, CreatedAt = DateTime.Now, Id = 0}));

            var hosts = new Hosts();
            var path = AppDomain.CurrentDomain.BaseDirectory + "MailHosts.xml";
            var sender = new NewsSenderManager(hosts.Load(path));

            sender.ProcessQueue(model.Body, model.Subject, recipients);
            return View("Index", new MailingModel { SendReturn = "enviado com sucesso." });
        }
示例#2
0
 static void SendOne()
 {
     var hosts = new Hosts();
     var path = AppDomain.CurrentDomain.BaseDirectory + "MailHosts.xml";
     var newsSender = new NewsSenderManager(hosts.Load(path));
     newsSender.ProcessQueue("Testando envio", "Testando envio", new List<Recipient>(new[] { new Recipient { Email = "*****@*****.**", Name = "chalk" } }));
     Console.WriteLine("Sent Test");
     Console.Read();
 }