Exemple #1
0
        /// <summary>
        /// Method for delete a mailbox.
        /// </summary>
        /// <param name="name">The mailbox name.</param>
        public void DeleteMailbox(string name)
        {
            // We remove all messages contained in mailbox
            Mailbox mailbox = this._imap4Client.SelectMailbox(name);

            mailbox.Empty(false);

            // We delete the mailbox from the account
            this._imap4Client.DeleteMailbox(name);
        }
        private void _bEmptyMailbox_Click(object sender, EventArgs e)
        {
            // We create Imap client
            Imap4Client imap = new Imap4Client();

            try
            {
                // We connect to the imap4 server
                imap.Connect(_tbImap4Server.Text);

                this.AddLogEntry(string.Format("Connection to {0} successfully", _tbImap4Server.Text));

                // Login to mail box
                imap.Login(_tbUserName.Text, _tbPassword.Text);

                this.AddLogEntry(string.Format("Login to {0} successfully", _tbImap4Server.Text));

                if (_tbMailboxToEmpty.Text.Length > 0)
                {
                    Mailbox mailbox = imap.SelectMailbox(_tbMailboxToEmpty.Text);
                    mailbox.Empty(false);
                    this.AddLogEntry(string.Format("Mailbox {0} successfully empty", _tbMailboxToEmpty.Text));
                }

                else
                {
                    this.AddLogEntry("You have to set a mailbox name to empty");
                }
            }

            catch (Imap4Exception iex)
            {
                this.AddLogEntry(string.Format("Imap4 Error: {0}", iex.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }

            finally
            {
                if (imap.IsConnected)
                {
                    imap.Disconnect();
                }
            }
        }