public ActionResult SendEmail(TOURIS_TV_CONTACT_US contactUs, HttpPostedFileBase postedFile)
        {
            ResultStatus rs         = new ResultStatus();
            MailMessage  mail       = new MailMessage();
            CUSTOM_MAIL  customMail = new CUSTOM_MAIL();

            string[] to      = { "*****@*****.**" };
            string[] from    = { "*****@*****.**" };
            string[] cc      = { contactUs.EMAIL_SENDER };
            string   subject = "[professionalis.me] Customer Service - " + contactUs.NAME_SENDER;
            string   body    = contactUs.DESCRIPTION;

            string attachmentName = "";

            if (postedFile != null)
            {
                attachmentName = postedFile.FileName;
            }

            if (ModelState.IsValid)
            {
                customMail.TO         = to;
                customMail.FROM       = from;
                customMail.CC         = cc;
                customMail.SUBJECT    = subject;
                customMail.BODY       = body;
                customMail.ISBODYHTML = true;
                try
                {
                    Email email = new Email();
                    mail = email.MappingEmail(customMail);
                    rs   = email.SendEmail(mail, attachmentName);
                    TempData["msgSuccess"] = rs.MessageText;
                }
                catch (DataException ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    rs.SetErrorStatus("Data failed to sent");
                    TempData["msgError"] = rs.MessageText;
                }
            }

            return(RedirectToAction("Contact"));
        }
Beispiel #2
0
        public MailMessage MappingEmail(CUSTOM_MAIL customMail)
        {
            MailMessage mail = new MailMessage();
            foreach (var from in customMail.FROM)
            {
                mail.From = new MailAddress(from, "CSProfessionalisme");
            }

            foreach (var to in customMail.TO)
            {
                mail.To.Add(new MailAddress(to));
            }

            foreach (var cc in customMail.CC)
            {
                mail.CC.Add(new MailAddress(cc));
            }

            mail.Subject = customMail.SUBJECT;
            mail.IsBodyHtml = customMail.ISBODYHTML;
            mail.Body = customMail.BODY;

            return mail;
        }