Beispiel #1
0
        private void dgvEmailInfo_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            strFrom     = strSubject = strBody = strDate = strAttachment = string.Empty;
            strFrom     = dgvEmailInfo.Rows[e.RowIndex].Cells[0].Value.ToString();
            strSubject  = dgvEmailInfo.Rows[e.RowIndex].Cells[1].Value.ToString();
            strBody     = dgvEmailInfo.Rows[e.RowIndex].Cells[2].Value.ToString();
            strDate     = dgvEmailInfo.Rows[e.RowIndex].Cells[4].Value.ToString();
            mailMessage = popMail.Messages[e.RowIndex + 1];
            atts        = mailMessage.Attachments;
            for (int k = 0; k < atts.Count; k++)
            {
                att = atts[k];
                if (strAttachment == string.Empty)
                {
                    strAttachment = ReplaceName(att.Name);
                }
                else
                {
                    strAttachment += "," + ReplaceName(att.Name);
                }
            }
            frmEmailInfo frmemailinfo = new frmEmailInfo();

            frmemailinfo.ShowDialog();
        }
Beispiel #2
0
 private void dgvEmailInfo_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.ColumnIndex == 3)
         {
             mailMessage = popMail.Messages[e.RowIndex + 1];
             atts        = mailMessage.Attachments;
             for (int k = 0; k < atts.Count; k++)
             {
                 att = atts[k];
                 string attname = att.Name;
                 Directory.CreateDirectory("AttachFiles\\" + user);
                 string mailPath = "AttachFiles\\" + user + "\\" + ReplaceName(att.Name);
                 att.SaveToFile(mailPath);
                 MessageBox.Show("下载成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     catch { }
 }
Beispiel #3
0
 private void frmMain_Load(object sender, EventArgs e)
 {
     //禁用DataGridView控件的排序功能
     for (int i = 0; i < dgvEmailInfo.Columns.Count; i++)
     {
         dgvEmailInfo.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
     }
     if (Database.StrName == "mr" || Database.StrName == "*****@*****.**")
     {
         用户管理ToolStripMenuItem.Visible = true;
     }
     else
     {
         用户管理ToolStripMenuItem.Visible = false;
     }
     if (Database.StrName.IndexOf("@") == -1)
     {
         DataSet myds = database.getDs("select * from tb_User where Name='" + Database.StrName + "'", "tb_User");
         user = myds.Tables[0].Rows[0][2].ToString();
         pwd  = myds.Tables[0].Rows[0][3].ToString();
     }
     else
     {
         user = Database.StrName;
         DataSet myds = database.getDs("select * from tb_User where Email='" + Database.StrName + "'", "tb_User");
         pwd = myds.Tables[0].Rows[0][3].ToString();
     }
     strserver = Dns.GetHostName();
     popMail   = new jmail.POP3Class();
     //调用Connect方法连接指定的邮箱
     try
     {
         popMail.Connect(user, pwd, strserver, 110);
         TLabUser.Text = user;
         TLabNum.Text  = popMail.Count + " 封";
         if (popMail.Count != 0)
         {
             dgvEmailInfo.RowCount = popMail.Count;
             if (popMail != null)
             {
                 if (popMail.Count > 0)//当邮箱中存在邮件的情况下运行代码
                 {
                     for (int i = 1; i < popMail.Count + 1; i++)
                     {
                         mailMessage = popMail.Messages[i];
                         if (mailMessage.From == user.Trim().ToLower())
                         {
                             dgvEmailInfo.Rows[i - 1].Cells[0].Value = "我";
                         }
                         else
                         {
                             dgvEmailInfo.Rows[i - 1].Cells[0].Value = mailMessage.From;
                         }
                         dgvEmailInfo.Rows[i - 1].Cells[1].Value = Base64Decode(mailMessage.Subject);
                         dgvEmailInfo.Rows[i - 1].Cells[2].Value = Base64Decode(mailMessage.Body);
                         dgvEmailInfo.Rows[i - 1].Cells[4].Value = mailMessage.Date.ToString();
                         if (popMail.Count >= 1 && i <= popMail.Count)
                         {
                             atts = mailMessage.Attachments;
                             if (atts.Count > 0)
                             {
                                 dgvEmailInfo.Rows[i - 1].Cells[3].Value = "附件下载";
                             }
                             else
                             {
                                 dgvEmailInfo.Rows[i - 1].Cells[3].Value = "无附件";
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             dgvEmailInfo.Rows.Clear();
         }
     }
     catch
     {
         MessageBox.Show("该用户邮箱不存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }