Exemplo n.º 1
0
        private void SendMail(SEMCustomerDetail model, string sEmail)
        {
            string strSmtpHost = "172.18.9.36";
            int iSmtpPort =25;

            // get from config file
            // smtp host
            string smtphostSetting = System.Configuration.ConfigurationManager.AppSettings["SmtpHost"];
            if (!String.IsNullOrEmpty(smtphostSetting))
                strSmtpHost = smtphostSetting;
            // smtp port
            string smtpportSetting = System.Configuration.ConfigurationManager.AppSettings["SmtpPort"];
            if (!String.IsNullOrEmpty(smtpportSetting))
                iSmtpPort = Convert.ToInt32(smtpportSetting);

            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient(strSmtpHost, iSmtpPort);

            mail.From = new MailAddress(model.email);
            mail.To.Add(sEmail);
            mail.Subject = "Semplest Website Inquiry";
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Name: " + model.FirstName + " " + model.LastName);
            sb.AppendLine("Company: " + model.Company);
            if (!String.IsNullOrEmpty(model.Phone))
                sb.AppendLine("Phone: " + model.Phone);
            if (!String.IsNullOrEmpty(model.email))
                sb.AppendLine("Email: " + model.email);

            mail.Body = sb.ToString();

            SmtpServer.Send(mail); 

        }
Exemplo n.º 2
0
        public ActionResult ContactUs(SEMCustomerDetail model)
        {
            if (ModelState.IsValid && !(model.CallMe == false && model.EmailMe == false))
            {
                try
                {
                    model.CreatedDate = DateTime.Now;
                    using (var dbContext = new SemplestModel.Semplest())
                    {
                        string semEmail = dbContext.Configurations.Select(m => m.DefalutEmailContactMe).FirstOrDefault();

                        if (model.EmailMe == false)
                        {
                            model.email = "";
                        }
                        else if (model.CallMe == false)
                        {
                            model.Phone = "";
                        }
                        dbContext.SEMCustomerDetails.Add(model);
                        dbContext.SaveChanges();

                        // send email using smtp server
                        if (model.EmailMe == true)
                            SendMail(model, semEmail);
                    }
                }
                catch (Exception ex)
                {
                    string errMsg = "Error: " + ex.Message + "\r\n" + ex.StackTrace;
                    var errModel = new ErrorModel() { MsgToLog = errMsg, MsgToShow = "Error" };
                    return View("ErrorPage", errModel);
                }
                return RedirectToAction("ThankYou");
            }
            else
            {

                return View(model);
            }
        }
Exemplo n.º 3
0
        private void SendMail(SEMCustomerDetail model, string sEmail)
        {
            using (SemplestModel.Semplest dbcontext = new SemplestModel.Semplest())
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Name: " + model.FirstName + " " + model.LastName);
                sb.AppendLine("Company: " + model.Company);
                if (!String.IsNullOrEmpty(model.Phone))
                    sb.AppendLine("Phone: " + model.Phone);
                if (!String.IsNullOrEmpty(model.email))
                    sb.AppendLine("Email: " + model.email);
                sb.AppendLine("Notes: " + model.notes);
                var scw = new ServiceClientWrapper();
                scw.SendEmail(dbcontext.Configurations.First().RunMode + " - Semplest Website Inquiry", "*****@*****.**", sEmail, sb.ToString());
            }

        }