예제 #1
0
        //发送邮件
        private void button_write_send_Click(object sender, EventArgs e)
        {
            if (DataService.smtp == null)
            {
                if (DataService.smtp.State == SmtpSTATE.CONNECTED)   //信息失效
                {
                    //程序显示登录界面
                    MessageForm messageForm = new MessageForm("提醒", "登录信息失效!", "注销", "取消");
                    messageForm.ShowDialog();
                    //显示主界面
                    if (messageForm.DialogResult == DialogResult.OK)
                    {
                        messageForm.Dispose();
                        Logout();
                    }
                    else if (messageForm.DialogResult == DialogResult.Cancel)
                    {
                        messageForm.Dispose();
                    }
                    return;
                }
            }
            string to      = textBox_write_to.Text;
            string subject = textBox_write_subject.Text;
            string content = textBox_write_content.Text;

            if (string.IsNullOrEmpty(to) || string.IsNullOrEmpty(subject) || string.IsNullOrEmpty(content))
            {
                MessageForm messageForm = new MessageForm("提醒", "输入不能为空", "确定");
                messageForm.ShowDialog();
                if (messageForm.DialogResult == DialogResult.Cancel)
                {
                    messageForm.Dispose();
                }
                return;
            }
            MessageForm messageForm2;

            if (DataService.smtp.SendMail(to, subject, content, listView_write_enclosures))
            {
                messageForm2 = new MessageForm("提醒", "发送成功", "确定");
            }
            else
            {
                messageForm2 = new MessageForm("提醒", "发送失败", "确定");
            }
            messageForm2.ShowDialog();
            if (messageForm2.DialogResult == DialogResult.Cancel)
            {
                messageForm2.Dispose();
            }
            ClearWritePanel();
            return;
        }
예제 #2
0
        //删除邮件
        private void  除邮件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // 获取邮件的真实index
            MessageForm messageForm = new MessageForm("警告", "确定删除该邮件吗?", "删除", "取消");

            messageForm.ShowDialog();
            if (messageForm.DialogResult == DialogResult.OK)
            {
                ReceivedMail mail = GetSelectedMail();
                DataService.pop3.DelMail(mail.Id);
                receivedMails.Remove(mail);
                //同步更新全局变量
                DataService.pop3.User.ReceivedMails = receivedMails;
                ReverseUpdate();
                listBox_receivedMails.Refresh();
            }
        }
예제 #3
0
        //添加附件
        private void button_write_enclosure_Click(object sender, EventArgs e)
        {
            if (listView_write_enclosures.Items.Count == 10)
            {
                MessageForm messageForm = new MessageForm("提醒", "附件个数不能超过10个!", "确定");
                messageForm.ShowDialog();
                if (messageForm.DialogResult == DialogResult.Cancel)
                {
                    messageForm.Dispose();
                }
                return;
            }
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Multiselect     = true;
            fileDialog.CheckFileExists = true;
            fileDialog.ValidateNames   = true;
            fileDialog.Title           = "请选择文件";
            fileDialog.Filter          = "所有文件(*.*)|*.*|文本(*.txt)|*.txt|图片(*.jpg)|*.jpg|压缩包(*.zip)|*.zip"; //设置要选择的文件的类型
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                foreach (string filePath in fileDialog.FileNames)
                {
                    if (new FileInfo(filePath).Length / 2014 / 1024 > 1024)
                    {
                        MessageBox.Show("文件大小不能超过1GB");
                    }
                    else
                    {
                        //listView_write_enclosures.Items.Add(filePath);
                        ListViewItem item = new ListViewItem();
                        item.ImageIndex = EnclosureUtil.GetEnclosuerIconIndex(filePath);
                        item.Text       = filePath;
                        listView_write_enclosures.Items.Add(item);
                    }
                }
            }
        }
예제 #4
0
        //登录
        private void button_login_Click(object sender, EventArgs e)
        {
            string username = comboBox_username.Text;
            string password = textBox_password.Text;

            //先判断是否有空,即信息未填完
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return;
            }

            //判断格式是否正确
            if (username.Split('@').Length != 2)
            {
                MessageForm messageForm = new MessageForm("提醒", "用户名格式不正确", "确定");
                messageForm.ShowDialog();
                if (messageForm.DialogResult == DialogResult.Cancel)
                {
                    messageForm.Dispose();
                }
                return;
            }

            User user = users.Find(u => u.Username.Equals(username));

            if (user == null)
            {
                user = new User(username, password);
            }

            //登录
            if (!LoginController.LoginPOP3(user, !users.Contains(user)) || !LoginController.LoginSMTP(DataService.pop3.User))
            {
                MessageForm messageForm = new MessageForm("提醒", "用户名或密码错误", "确定");
                messageForm.ShowDialog();
                if (messageForm.DialogResult == DialogResult.Cancel)
                {
                    messageForm.Dispose();
                }
            }
            else
            {
                if (checkBox1.Checked)
                {
                    DataService.pop3.User.RemUser = true;
                }
                else
                {
                    DataService.pop3.User.RemUser = false;
                }
                if (checkBox2.Checked)
                {
                    DataService.pop3.User.RemPass = true;
                }
                else
                {
                    DataService.pop3.User.RemPass = false;
                }
                this.DialogResult = DialogResult.OK;
            }
        }