示例#1
0
        private void buttonAutodiscover_Click(object sender, EventArgs e)
        {
            string sDomain = "";

            try
            {
                sDomain = textBoxSMTP.Text.Substring(textBoxSMTP.Text.IndexOf('@') + 1);
            }
            catch { }
            if (String.IsNullOrEmpty(sDomain))
            {
                System.Windows.Forms.MessageBox.Show("Invalid email address", "Error",
                                                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            SetFormControls(false);
            Application.UseWaitCursor = true;
            Application.DoEvents();

            ClassEWSAutodiscover oAutoDiscover = new ClassEWSAutodiscover(textBoxSMTP.Text, Credentials, listBoxLog, _logger);

            oAutoDiscover.IgnoreCertificateErrors = checkBoxIgnoreCertificateErrors.Checked;
            if (oAutoDiscover.Autodiscover(checkBoxSkipSCPAutodiscover.Checked))
            {
                // Successfully retrieved settings
                _EWSUrl = oAutoDiscover.EWSUrl;

                // Set the target control (if we have one... ignore any errors)
                try
                {
                    Type t = _targetControl.GetType();
                    t.InvokeMember("Text", System.Reflection.BindingFlags.SetProperty, null, _targetControl, new object[] { oAutoDiscover.EWSUrl });
                }
                catch { }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Unable to determine EWS URL", "AutoDiscover failed",
                                                     MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            SetFormControls(true);
            Application.UseWaitCursor = false;
            buttonClose.Enabled       = true;
        }
        private void buttonTest_Click(object sender, EventArgs e)
        {
            if (radioButtonAutodiscover.Checked)
            {
                // Perform autodiscover
                ClassEWSAutodiscover autodiscover = new ClassEWSAutodiscover(textBoxAutodiscoverEmail.Text, _mainform.CredentialHandler(), listBoxLog, _logger);
                if (autodiscover.Autodiscover())
                {
                    textBoxEWSUrl.Text = autodiscover.EWSUrl;
                    textBoxEWSUrl.Refresh();
                }
                else
                {
                    // Autodiscover failed
                    System.Windows.Forms.MessageBox.Show("Failed to obtain EWS Url.", "Autodiscover failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // We now have an EWS Url, let's do some basic EWS tasks
            if (checkBoxInboxFindItems.Checked)
            {
            }
        }