protected void SendTestEmail_Click(object sender, EventArgs e)
        {
            string body = string.Format("<p>This is a test email from {0} sent at {1}.</p>",
                GetSettingValue("SysName"),
                DateTime.Now.ToString());

            var emailService = new EmailService();
            emailService.SendEmail(this.EmailTo.Text, this.EmailSubject.Text, body);
            if (emailService.ErrorException == null)
            {
                AlertPanel.Visible = true;
                AlertPanel.CssClass = "alert alert-success";
                AlertGlyphicon.Attributes.Add("class", "glyphicon glyphicon-ok");
                AlertMessage.Text = string.Format("Message successfully sent to {0}.",
                    this.EmailTo.Text);
            }
            else
            {
                AlertPanel.Visible = true;
                AlertPanel.CssClass = "alert alert-danger";
                AlertGlyphicon.Attributes.Add("class", "glyphicon glyphicon-remove");
                var sb = new StringBuilder("An error occurred sending the test email: <strong>");
                sb.Append(emailService.ErrorException.Message);
                sb.Append("</strong><p>Detailed error:</p><pre>");
                var ex = emailService.ErrorException;
                while (ex != null)
                {
                    sb.Append(ex.StackTrace);
                    ex = ex.InnerException;
                }
                sb.Append("</pre>");
                AlertMessage.Text = sb.ToString();
            }
        }
        protected void SendTestMail(object sender, EventArgs e)
        {
            if(Page.IsValid) {
                HandlePasswordFields(MailPassword, MailPwKey);

                var service = new EmailService {
                    TestEmailDuringSetup = true
                };

                if(!string.IsNullOrEmpty(MailServer.Text)) {
                    service.Server = MailServer.Text;
                }

                if(!string.IsNullOrEmpty(MailPort.Text)) {
                    int port = 0;
                    if(int.TryParse(MailPort.Text, out port)) {
                        service.Port = port;
                    }
                }

                if(!string.IsNullOrEmpty(MailLogin.Text)) {
                    service.Login = MailLogin.Text;
                }

                if(!string.IsNullOrEmpty(MailPassword.Text)) {
                    service.Password = MailPassword.Text;
                }

                if(service.SendEmail(MailAddress.Text,
                                     MailAddress.Text,
                                     "Test email during Great Reading Adventure setup",
                                     "This is an email sent during the setup of the Great Reading Adventure software to ensure the mail settings are correct!")) {
                    this.MailSuccessPanel.Visible = true;
                } else {
                    this.MailIssuePanel.Visible = true;
                    this.MailIssueMessage.Text = string.Format("There was a problem sending the test message: {0}", service.Error);
                }
                ShowStep((int)ViewState[StepKey], true);
            }
        }