public void supprMailIMAP(string userName, string psw, string service, bool ssl, int port, string mailsupprBegin, string mailsupprEnd)
        {
            IMAP_Client imapc      = loginMail(userName, psw, service, ssl, port);
            var         folderlist = imapc.GetFolders(null);

            imapc.SelectFolder("INBOX");
            var folder = imapc.SelectedFolder;
            var seqSet = IMAP_t_SeqSet.Parse("@begin:@end".Replace("@begin", mailsupprBegin).Replace("@end", mailsupprEnd));
            var items  = new IMAP_t_Fetch_i[]
            {
                new IMAP_t_Fetch_i_Envelope(),
                new IMAP_t_Fetch_i_Uid(),
                new IMAP_t_Fetch_i_Flags(),
                new IMAP_t_Fetch_i_InternalDate(),
                new IMAP_t_Fetch_i_Rfc822()
            };

            try
            {
                imapc.StoreMessageFlags(true, seqSet, IMAP_Flags_SetType.Add, new IMAP_t_MsgFlags(new string[] { IMAP_t_MsgFlags.Deleted }));
            }
            catch
            {
            }
            imapc.Disconnect();
        }
Beispiel #2
0
 public void Disconnect()
 {
     if (IsConnected)
     {
         Client.Disconnect();
     }
 }
        public void getMailSendImap(string userName, string psw, string service, bool ssl, int port)
        {
            try
            {
                IMAP_Client imapc      = loginMail(userName, psw, service, ssl, port);
                var         folderlist = imapc.GetFolders(null);
                imapc.SelectFolder("Éléments envoyés");
                //imapc.SelectFolder("INBOX");
                var folder = imapc.SelectedFolder;
                var seqSet = IMAP_t_SeqSet.Parse("1:*");
                var items  = new IMAP_t_Fetch_i[]
                {
                    new IMAP_t_Fetch_i_Envelope(),
                    new IMAP_t_Fetch_i_Uid(),
                    new IMAP_t_Fetch_i_Flags(),
                    new IMAP_t_Fetch_i_InternalDate(),
                    new IMAP_t_Fetch_i_Rfc822()
                };

                imapc.Fetch(false, seqSet, items, this.m_pImap_Fetch_MessageItems_UntaggedResponse);
                System.Threading.Thread.Sleep(500);
                DataTable      dtmail           = datalistmail.getInstance().getdtSend();
                SqlDataAdapter adapteremailrecu = CreerDataAdapterFormail("MailSend");
                dtmail.DefaultView.Sort = "maildateTime DESC";
                int tr   = adapteremailrecu.Update(dtmail.Select(null, null, DataViewRowState.ModifiedCurrent));
                int tr12 = adapteremailrecu.Update(dtmail.Select(null, null, DataViewRowState.Added));
                //System.Threading.Thread.Sleep(500);
                imapc.Disconnect();
            }
            catch (Exception ex)
            {
                Console.WriteLine("ErrGetMail:" + ex.Message);
            }
        }
Beispiel #4
0
        public override Server creack(String ip, int port, String username, String password, int timeOut)
        {
            IMAP_Client conn   = null;
            Server      server = new Server();

            try
            {
                conn = new IMAP_Client();
                //与IMAP服务器建立连接
                conn.Timeout = timeOut;
                conn.Connect(ip, port, true);
                if (conn.IsConnected)
                {
                    conn.Login(username, password);

                    if (conn.IsAuthenticated)
                    {
                        server.isSuccess = conn.IsAuthenticated;
                        server.banner    = conn.GreetingText;
                    }
                }
            }
            catch (Exception e) {
                throw e;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Disconnect();
                }
            }
            return(server);
        }
        public override void Close()
        {
            if (client != null && client.IsConnected)
            {
                client.Disconnect();
            }

            channelState = ChannelState.Closed;
        }
Beispiel #6
0
 private void Disconnect()
 {
     try {
         if (_client != null && _client.IsConnected)
         {
             _client.Disconnect();
         }
     } catch (Exception ex) {
         //Debug.WriteLine(this.GetType().Name + ": " + ex.Message);
         AppJournal.Write(GetType().Name + ": " + ex.Message);
     }
 }
        public IMAP_Client loginMail(string userName, string psw, string service, bool ssl, int port)
        {
            IMAP_Client imapc = new IMAP_Client();

            try
            {
                if (imapc.IsConnected)
                {
                    imapc.Disconnect();
                }
                imapc.Connect(service, port, ssl);
                imapc.Login(userName, psw);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ErrConnect:" + ex.Message);
            }
            return(imapc);
        }
Beispiel #8
0
        //#region 获取当前外网ip地址
        //private string GetIP()
        //{
        //    string strUrl = "http://www.ip138.com/ip2city.asp"; //获得IP的网址了
        //    Uri uri = new Uri(strUrl);
        //    WebRequest wr = WebRequest.Create(uri);
        //    Stream s = wr.GetResponse().GetResponseStream();
        //    StreamReader sr = new StreamReader(s, Encoding.Default);
        //    string all = sr.ReadToEnd(); //读取网站的数据
        //    int i = all.IndexOf("[") + 1;
        //    string tempip = all.Substring(i, 15);
        //    string ip = tempip.Replace("]", "").Replace(" ", "");
        //    return ip;
        //}
        //#endregion


        #region 未读邮件信息

        private void QueryEmailStatus()
        {
            IMAP_Client IMAPServer = new IMAP_Client();

            try
            {
                //连接邮件服务器通过传入邮件服务器地址和用于IMAP协议的端口号
                IMAPServer.Connect(@"imap.exmail.sina.com", 143, false);
                string currUserCode  = UserInfo.GetInstence().UserCode;
                string emailPassword = string.Empty;
                //登陆邮箱,前者帐号后者密码
                using (var context = new BugTraceEntities(EntityContextHelper.GetEntityConnString()))
                {
                    var currUserExt = context.SYS_UserExt.Where(p => p.UserCode == currUserCode).FirstOrDefault();
                    if (currUserExt != null)
                    {
                        emailPassword = Encrypt.TripleDESDecrypting(currUserExt.EmailPassword);
                    }
                }
                if (string.IsNullOrWhiteSpace(emailPassword))
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        this.lblEmailInfo.Text = "邮箱登陆失败!请先在个人设置中设置密码!";
                    }));
                    return;
                }
                IMAPServer.Login(currUserCode + "@ecode.net.cn", emailPassword);

                //选中收件箱
                IMAPServer.SelectFolder("INBOX");

                //取出收件箱
                var folder = IMAPServer.SelectedFolder;

                //收件箱邮件总数
                //folder.MessagesCount.ToString();
                //收件箱未读邮件总数
                //folder.RecentMessagesCount.ToString();



                //以下开始取出邮件
                //首先确定取第x到第n封邮件,"1:*"表示第1封到最后一封
                int msgCount = folder.MessagesCount - 20;
                if (msgCount <= 0)
                {
                    msgCount = 1;
                }
                var seqSet = LumiSoft.Net.IMAP.IMAP_t_SeqSet.Parse(msgCount.ToString() + ":*");
                //根据数组中的成员决定取出邮件的那些信息
                var imap_t_Fetch_i = new IMAP_t_Fetch_i[]
                {   
                  new IMAP_t_Fetch_i_Envelope(),     //邮件的标题、正文等信息
                  new IMAP_t_Fetch_i_Flags(),        //此邮件的标志,应该是已读未读标志
                  new IMAP_t_Fetch_i_InternalDate(), //貌似是收到的日期
                  //new IMAP_t_Fetch_i_Rfc822(),//Rfc822是标准的邮件数据流,可以通过Lumisoft.Net.Mail.Mail_Message对象解析出邮件的所有信息(不确定有没有附件的内容)。
                  new IMAP_t_Fetch_i_Uid()           //返回邮件的UID号,UID号是唯一标识邮件的一个号码
                };
                //创建一个符合lumisoft的回调函数的委托。
                //当调用fetch函数完成时,会自动调用用户自定义的函数,这里是Fetchcallback(我自己起的名字,名字无意义,保证参数是object,LumiSoft . Net . EventArgs<IMAP_r_u> 两个就好
                EventHandler <LumiSoft.Net.EventArgs <IMAP_r_u> > lumisoftHandler = new EventHandler <LumiSoft.Net.EventArgs <IMAP_r_u> >(Fetchcallback);

                //把上边定义好的参数传入fetch函数,就会取出邮件
                //lumisoftHandler指向的函数在每取出一封邮件的时候会被触发一次
                IMAPServer.Fetch(false, seqSet, imap_t_Fetch_i, lumisoftHandler);
                this.Invoke(new MethodInvoker(delegate
                {
                    this.lblEmailInfo.Text     = "";
                    this.linkEmailInfo.Text    = "您当前共有" + UnReadEmailCount + "封未读邮件!<<click me>>(只搜索最近20封邮件)";
                    this.linkEmailInfo.Visible = true;
                    this.dgvEmail.DataSource   = dtblEmail;
                }));
            }
            catch (Exception ex)
            {
                MyLog.LogError("读取未读邮件失败!", ex);
                if (ex.Message.IndexOf("Invalid login credentials") != -1)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        this.lblEmailInfo.Text = "邮箱登陆失败!请先在个人设置中设置密码!";
                    }));
                }
            }
            finally
            {
                IMAPServer.Disconnect();
            }
        }
Beispiel #9
0
 public void disconnect()
 {
     client.Disconnect();
     //client.Dispose();
     Console.Out.WriteLine("метод disconnect");
 }