Example #1
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);
                    }
                }
            }
        }
Example #2
0
        //显示邮件内容
        private void ShowMailText(ReceivedMail receivedMail)
        {
            if (receivedMail == null)
            {
                label_sender.Text            = "发件人:";
                label_receiver.Text          = "收件人:";
                label_subject.Text           = "主  题:";
                label_date_detail.Text       = "时间:";
                label_size.Text              = "大  小:  KB";
                label_enclosure.Text         = "附  件: ";
                richTextBox_content.Text     = "";
                webBrowser_html.DocumentText = "";
                listView_enclosure.Items.Clear();
                webBrowser_html.Visible     = false;
                richTextBox_content.Visible = true;

                groupBox_infos.Size          = new Size(groupBox_infos.Size.Width, 156);
                richTextBox_content.Location = new Point(richTextBox_content.Location.X, 330 - 160);
                richTextBox_content.Size     = new Size(richTextBox_content.Size.Width, 355 + 160);
                webBrowser_html.Location     = new Point(webBrowser_html.Location.X, 355 - 160);
                webBrowser_html.Size         = new Size(groupBox_infos.Size.Width, 355 + 160);
                return;
            }

            label_sender.Text        = "发件人:" + receivedMail.FromName + " <" + receivedMail.FromAddress + ">";
            label_receiver.Text      = "收件人:" + receivedMail.ToName + " <" + receivedMail.ToAdderss + ">";
            label_subject.Text       = "主  题:" + receivedMail.Subject;
            label_date_detail.Text   = "时间:" + receivedMail.SendDateTime.ToString();
            label_size.Text          = "大  小:" + receivedMail.Size.ToString() + " KB";
            label_enclosure.Text     = "附  件:(已下载于" + EnclosureUtil.GetDirOrPath() + ")";
            richTextBox_content.Text = receivedMail.Body;
            int len = receivedMail.Enclosures.Count;

            listView_enclosure.Items.Clear();
            webBrowser_html.Visible     = false;
            richTextBox_content.Visible = true;
            if (len == 0)
            {
                groupBox_infos.Size          = new Size(groupBox_infos.Size.Width, 156);
                richTextBox_content.Location = new Point(richTextBox_content.Location.X, 330 - 160);
                richTextBox_content.Size     = new Size(richTextBox_content.Size.Width, 355 + 160);
                webBrowser_html.Location     = new Point(webBrowser_html.Location.X, 355 - 160);
                webBrowser_html.Size         = new Size(groupBox_infos.Size.Width, 355 + 160);
            }
            else
            {
                groupBox_infos.Size          = new Size(groupBox_infos.Size.Width, 304);
                richTextBox_content.Location = new Point(richTextBox_content.Location.X, 330);
                richTextBox_content.Size     = new Size(richTextBox_content.Size.Width, 355);
                webBrowser_html.Location     = new Point(webBrowser_html.Location.X, 330);
                webBrowser_html.Size         = new Size(webBrowser_html.Size.Width, 355);

                for (int i = 0; i < len; i++)
                {
                    ListViewItem item     = new ListViewItem();
                    string       filename = receivedMail.Enclosures[i];
                    item.ImageIndex = EnclosureUtil.GetEnclosuerIconIndex(filename);
                    item.Text       = filename;
                    listView_enclosure.Items.Add(item);
                }
            }

            ReceivedMail mail = GetSelectedMail();

            if (mail != null && !mail.IsText)
            {
                webBrowser_html.Visible      = true;
                richTextBox_content.Visible  = false;
                webBrowser_html.DocumentText = mail.Html;
            }
        }