コード例 #1
0
        public ActionResult Step2(MailInstallViewModel info)
        {
            ViewData["StepNumber"] = 2;

            if (info.MailUseDefaultCredentials)
            {
                ModelState.Remove("MailLogin");
                ModelState.Remove("MailPassword");
            }

            if (!ModelState.IsValid)
                return View(info);

            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Host = info.MailServerAddress;
            smtpClient.Port = info.PortNumber;
            smtpClient.UseDefaultCredentials = info.MailUseDefaultCredentials;
            if (!info.MailUseDefaultCredentials)
                smtpClient.Credentials = new NetworkCredential(info.MailLogin, info.MailPassword);

            try
            {
                smtpClient.Send("no-reply@" + Request.Url.Host, "test@" + smtpClient.Host, "", "");
            }
            catch (Exception ex)
            {
                ViewData[ViewDataKeys.GlobalMessages.Notice] = "Error connecting to SMTP server, a " + ex.GetType().ToString() + " exception was raised";
                ViewData[ViewDataKeys.GlobalMessages.Error] = ex.Message;
                return View(info);
            }

            Session[SessionMailInfoKey] = info;
            return RedirectToAction("Step3");
        }
コード例 #2
0
        public ActionResult Step2()
        {
            ViewData["StepNumber"] = 2;

            if (Session[SessionSqlInfoKey] != null)
                ViewData[ViewDataKeys.GlobalMessages.Success] = "Successfully connected to database and created tables";

            MailInstallViewModel model = new MailInstallViewModel
            {
                MailServerAddress = "mail." + Request.Url.Host,
                MailUseDefaultCredentials = false,
                PortNumber = 25
            };

            return View(model);
        }