コード例 #1
0
ファイル: SettingsForm.cs プロジェクト: Woodje/MailClient
        private void ReadSettings()
        {
            // Check if the other form is open, if it is not then close this one.
            if (Application.OpenForms["MailClientForm"] == null)
                Close();

            // Instantiate the database.
            settingsDatabase = new SettingsDatabase();

            // Go through all the retrieved settings from the database.
            foreach (SettingsDatabase.UserSettings value in settingsDatabase.ReadUserSettings())
            {
                // Find the record which matches the usermail and password.
                if (Application.OpenForms["MailClientForm"].Controls["textBoxMail"].Text == value.userMail && Application.OpenForms["MailClientForm"].Controls["textBoxPassword"].Text == value.password)
                {
                    // Write the retrieved values to the textboxes.
                    textBoxReceiveServer.Text = value.receiveServer;
                    textBoxReceivePort.Text = value.receivePort.ToString();
                    textBoxReceiveSSL.Text = value.receiveSSL;
                    textBoxSendServer.Text = value.sendServer;
                    textBoxSendPort.Text = value.sendPort.ToString();
                    textBoxSendSSL.Text = value.sendSSL;

                    // Break out of the loop because a match is found.
                    break;
                }
            }
        }
コード例 #2
0
ファイル: ConnectToServer.cs プロジェクト: Woodje/MailClient
        private void InitConnectionToServer()
        {
            // Instantiating the client.
            client = new Pop3Client();

            // Instantiate the database.
            settingsDatabase = new SettingsDatabase();

            // Change the programs status to be in loading state.
            MailClientForm.SetProgramStatus(MailClientForm.ProgramStatus.Loading);

            // Output that connection to the server is being made.
            ComponentChanges.ReplaceLabelText(status, "Connecting to server");

            // Go through all the user records in the database.
            foreach (SettingsDatabase.UserSettings value in settingsDatabase.ReadUserSettings())
            {
                // Check if the record in the database matches the usermail and password.
                if (userMail == value.userMail && password == value.password)
                {
                    // Start connection to the server with the values from the database.
                    client.Connect(value.receiveServer, value.receivePort, bool.Parse(value.receiveSSL));

                    // Break out of the loop because a match is found.
                    break;
                }
            }

            // Check if the Pop3Client is connected.
            if (client.Connected)
            {
                // Output that connection to the server is established.
                ComponentChanges.ReplaceLabelText(status, "Connected to server");

                // Set the programs status to be connected to the mail server.
                MailClientForm.SetProgramStatus(MailClientForm.ProgramStatus.ConnectedToServer);

                // Announce that we are done with the establishment of the connection.
                ComponentChanges.ReplaceProgressBarValue(statusProgressBar, 100);
            }
            else
            {
                // Output that connection to the server is not established.
                ComponentChanges.ReplaceLabelText(status, "Disconnected");

                // Set the programs status to be disconnected.
                MailClientForm.SetProgramStatus(MailClientForm.ProgramStatus.Disconnected);

                // Announce that we are done with the establishment of the connection.
                ComponentChanges.ReplaceProgressBarValue(statusProgressBar, 100);
            }

            // Authenticate the user.
            client.Authenticate(userMail, password);

            // Output that autentication is accepted.
            ComponentChanges.ReplaceLabelText(status, "Connected");

            // Set the programs status to be connected.
            MailClientForm.SetProgramStatus(MailClientForm.ProgramStatus.Connected);

            // Announce that we are done with the establishment of the connection.
            ComponentChanges.ReplaceProgressBarValue(statusProgressBar, 100);

            // Check if it is time to check for new mail on the server.
            if (checkForNewMail)
                // Check if any new mails is present.
                CheckForNewMail(listBoxMails);

            // Check if any mails is pending for sending.
            if (listEmailsPending.Count > 0)
                // Send the email from the pending list.
                SendPendingEmails();
        }