试了很多办法,都不能实现程序读取GMAIL邮件内容,想问有这方面经验的朋友有没有好的解决办法,谢了先

解决方案 »

  1.   

    用Socket的方法不行吗?分析一下MIME格式的文件应该还是可以的吧。如果麻烦的话就用Jmail来做也应该可以的吧。楼主把
    问题再详细描述一下吧~~
      

  2.   

    主要是Gmail有一个SSL验证问题,普通的邮箱我已经实现了程序收发,就是不知如何处理这个SSL问题,GOOGLE API里好像也没有
      

  3.   


              //SendMail
            private void sendMail(MailMessage mail)
            {
                SmtpClient smtpClient = new SmtpClient();
                //是否SSL
                if (M_SendMail.Ts_Mail_SMTP_SSL == 0)
                {
                    smtpClient.EnableSsl = false;
                }
                else
                {
                    smtpClient.EnableSsl = true;
                }            smtpClient.Host = M_SendMail.Ts_Mail_SMTP_Address;              //smtp主机名
                smtpClient.Port = M_SendMail.Ts_Mail_SMTP_Port; ;               //smtp 端口     
                smtpClient.Credentials = new NetworkCredential("用户名","密码");//用户名  密码            smtpClient.Send(mail);        }     
            private void toolStripButton1_Click(object sender, EventArgs e)
            {
                MailMessage mailMessage = new MailMessage();
                string strBody;
                mailMessage.From = new MailAddress(Txt_FJR.Text.Trim());       //发件人
                mailMessage.Subject = Txt_Title.Text.Trim();                   //主题
                strBody = editor1.DocumentText;                                    //内容
                mailMessage.Body = strBody;                                     //内容
                mailMessage.IsBodyHtml = true;                                  //是否HTML
                mailMessage.BodyEncoding = Encoding.GetEncoding("UTF-8");       //邮件编码
                mailMessage.SubjectEncoding = Encoding.GetEncoding("UTF-8");    //主题编码
                ////添加附件
                for (int i = 0; i < Txt_FJ.Items.Count; i++)
                {
                    mailMessage.Attachments.Add(new Attachment(Txt_FJ.Items[i].ToString()));
                }            //-**********************************显示发送状态*********************//
                label6.Visible = true;
                System.Windows.Forms.Application.DoEvents();
                //-**********************************显示发送状态*********************//
                //mailMessage.Priority = System.Net.Mail.MailPriority.High;         //邮件优先级
                if (listBox1.Visible == false)
                {
                    //单发
                    if (Txt_SJR.Text.Trim() == "" )
                    {
                        MessageBox.Show("收件人不能为空!");
                        Txt_SJR.Focus();
                        return;
                    }
                    mailMessage.To.Add(Txt_SJR.Text.Trim());                       //收件人
                    try
                    {
                        sendMail(mailMessage);
                        MessageBox.Show("发送成功!");
                        PubFunction.write_System_Log("发送邮件", "发送邮件(" + Txt_SJR.Text.Trim() + ")成功", 1);
                    }
                    catch (Exception ex)
                    {
                        //throw new Exception("发送失败!");
                        PubFunction.write_System_Log("发送邮件", "发送邮件(" + Txt_SJR.Text.Trim() + ")失败", 1);
                        BasicConfigurator.Configure();
                        log.Error(ex);
                    }
                }
                else
                {
                    //群发
                    string strDepIDs = string.Empty;
                    System.Collections.ArrayList mailArr = new System.Collections.ArrayList();
                    for (int i = 0; i < listBox1.Items.Count; i++)
                    {
                       strDepIDs += Comm.Select_User[i].ToString().Split(',')[1] + "," ;
                    }
                    strDepIDs = strDepIDs.Substring(0, strDepIDs.Length - 1);
                    mailArr.AddRange(B_ts_send_mail.get_send_user(strDepIDs));
                    if (!mailArr.Count.Equals(0))
                    {
                        progressBar1.Maximum = mailArr.Count;                    for (int intj = 0; intj < mailArr.Count; intj++)
                        {
                            mailMessage.To.Add(mailArr[intj].ToString());
                            try
                            {
                                sendMail(mailMessage);                            progressBar1.Value = intj + 1;
                                System.Windows.Forms.Application.DoEvents();                            PubFunction.write_System_Log("发送邮件", "发送邮件(" + Txt_FJR.Text.Trim() + ")成功", 1);
                            }
                            catch (Exception ex)
                            {
                                //throw new Exception("发送失败!");
                                progressBar1.Value = intj + 1;
                                PubFunction.write_System_Log("发送邮件", "发送邮件(" + Txt_FJR.Text.Trim() + ")失败", 1);
                                BasicConfigurator.Configure();
                                log.Error(ex);
                            }
                        }
                        MessageBox.Show("发送成功!");
                    }
                    else
                    {
                        MessageBox.Show("收件人不能为空!");
                        label6.Visible = false;
                        return;
                    }            }
                label6.Visible = false;
                progressBar1.Value = 0;        }
      

  4.   

    在邮箱里设置POP3服务器开启
    然后用TCP连接23端口 
    解析发来的TEXT 最方便
      

  5.   

    wl076,感谢你的代码,不过我要的是接收不是发送,现在我已经实现了POP3收GMAIL功能,感谢大家,分平均的给吧:)如果有人对此感兴趣,可以与我联系:28688028