示例#1
0
        private List<string> GetEmails(ComposeMailModel model)
        {
            var list = new List<string>();

            if (model.SendToAllRegisteredCustomer)
            {
                list.AddRange(ServiceHelper.Customer.ExecuteDispose(s => s.GetAllEmails()));
            }

            var arr = model.Emails.ToStr().Split(new[] {";"}, StringSplitOptions.RemoveEmptyEntries).ToList();
            list.AddRange(arr);

            list = list.Select(s => s.ToLower()).Distinct().Where(std.IsEmail).ToList();

            return list;
        }
示例#2
0
        public ActionResult Send(ComposeMailModel model)
        {
            if (ModelState.IsValid)
            {
                var emails = GetEmails(model);

                if (!emails.Any())
                {
                    return JsonObject(false, GuiMail.ThereNoValidEmail);
                }

                var mail = new MailMessage();
                mail.To.Add(emails.First());
                if (emails.Count > 1)
                {
                    emails.Where(i=>i != emails.First()).ForEach(mail.Bcc.Add);
                }

                mail.Subject = model.Subject;
                mail.Body = model.Content;
                mail.IsBodyHtml = true;

                for (var i = 0; i < Request.Files.Count; ++i)
                {
                    var file = Request.Files[i];
                    if (file != null &&
                        !string.IsNullOrWhiteSpace(file.FileName))
                    {
                        var attachment = new Attachment(file.InputStream, file.FileName, file.ContentType);
                        mail.Attachments.Add(attachment);
                    }
                }

                EmailUtils.Instance.SendEmail(mail);

                return JsonObject(true, GuiMail.SendEmailSuccessful);
            }

            return JsonObject(false, GetModelStateErrors());
        }
示例#3
0
 public ActionResult Index()
 {
     var model = new ComposeMailModel();
     return View(model);
 }