Esempio n. 1
0
 public static bool SendContactUsMail(ContactModel contactModel)
 {
     string messageBody = string.Format(ContactUsMailTemplate, contactModel.Message, contactModel.Name,
                                        contactModel.Email, contactModel.PhoneNumber, contactModel.CompanyName);
     var smtp = new SmtpClient();
     var message = new MailMessage { IsBodyHtml = true, Body = messageBody, Subject = ContactUsMailSubject };
     string mailTo = ConfigurationManager.AppSettings["ContactUsMailTo"];
     string mailsCc = ConfigurationManager.AppSettings["ContactUsMailCC"];
     try
     {
         message.To.Add(mailTo);
         if (!string.IsNullOrWhiteSpace(mailsCc))
             message.CC.Add(mailsCc);
         if (contactModel.Attachment != null)
         {
             var attach = new Attachment(contactModel.Attachment.InputStream, contactModel.Attachment.FileName)
                              {
                                  ContentType = new ContentType(contactModel.Attachment.ContentType),
                              };
             message.Attachments.Add(attach);
         }
         smtp.Send(message);
     }
     catch (Exception)
     {
         return false;
     }
     return true;
 }
 public ActionResult ExtendedContact(ContactModel model)
 {
     if (!ModelState.IsValid)
         return View(model);
     bool isSended = Mailer.SendContactUsMail(model);
     TempData["SendContactUsMailResult"] = isSended
                         ? "Your request has been successfully sent. Our manager contact you as soon as possible."
                         : "Your request has not been sent.Please, try again...";
     return isSended ? View(model) : View();
 }
        public ActionResult Contact(ContactModel model)
        {
            //TODO: need move strings to resource files and wrap result to object
            var isSended = false;
            if (!ModelState.IsValid) return Content("{\"isSuccess\": false,\"message\": \"Your request has not been sent.Please, try again...\"}");

            try { isSended = Mailer.SendContactUsMail(model); }
            catch { if (!ModelState.IsValid) return Content("{\"isSuccess\": false,\"message\": \"Your request has not been sent.Please, try again...\"}"); }

            string result = isSended
                                   ? "Your request has been successfully sent. Our manager contact you as soon as possible."
                                   : "Your request hasn't been sent. Please, try again...";

            return Content(string.Format("{{\"isSuccess\": {0}, \"message\": \"{1}\"}}", isSended.ToString().ToLower(), result));
        }