Beispiel #1
0
        public ActionResult BulkEmail(BulkEmailModel model, HttpPostedFileBase attachment)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    String name     = model.Name;
                    String contents = model.Contents;
                    //String attachment = model.Attachment;
                    //String fileAttachment = attachment.FileName;


                    string saveName = "";

                    if (attachment != null)
                    {
                        string path   = Server.MapPath("~/Uploads/Attachments/");
                        string strExt = Path.GetExtension(attachment.FileName);
                        saveName = (name + "-" + $@"{DateTime.Now.Ticks}" + strExt);

                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        if ((strExt != ".pdf" && strExt != ".txt"))
                        {
                            ViewBag.Message = "Invalid File Type (Must be .pdf)";
                        }
                        else
                        {
                            attachment.SaveAs(path + Path.GetFileName(saveName));
                            ViewBag.Message = "File uploaded successfully.";
                        }
                    }


                    BulkEmailSender es = new BulkEmailSender();
                    es.BulkSend(name, contents, saveName);

                    ViewBag.Result = "Email has been sent";

                    ModelState.Clear();

                    return(View(new BulkEmailModel()));
                }
                catch
                {
                    ViewBag.Result = "Email Failed!";
                    return(View());
                }
            }

            return(View());
        }
        public IActionResult SendEmails()
        {
            try
            {
                Queue <MailMessage> surveyMessageQ = BulkEmailModel.GetEmailMessageQInstance();

                //TODO : Send Emails, DeQueue, Consider the email server send limitations(Per minute how many Emails can be send)
            }
            catch (Exception ex)
            {
                throw;
            }

            return(View());
        }
        public IActionResult AddEmailsToQueue(int emailCount)
        {
            try
            {
                Queue <MailMessage> surveyMessageQ = BulkEmailModel.GetEmailMessageQInstance();

                //TODO : Create emails and add to queue
            }
            catch (Exception ex)
            {
                throw;
            }

            TempData["SuccessMsg"] = "Emails queued successfully";

            return(RedirectToAction("Index", "Home"));
        }