public void ReceiveMails(string Username, int OrderID) { //jmail.Message Msg=new jmail.Message(); //jmail.POP3 jpop = new jmail.POP3(); if (OrderID != 0) { SqlDataReader dataReader = this.ExtGetSetting(Username, OrderID); if (dataReader.Read()) { if (dataReader["PopServer"].ToString() != "" && dataReader["PopUsername"].ToString() != "") { //jpop.Connect(dataReader["PopUsername"].ToString(),dataReader["PopPassword"].ToString(),dataReader["PopServer"].ToString(),Int32.Parse(dataReader["PopPort"].ToString())); Pop3Client cl = new Pop3Client(dataReader["PopServer"].ToString()); cl.UserName = dataReader["PopUsername"].ToString(); cl.Password = dataReader["PopPassword"].ToString(); cl.Port = Int32.Parse(dataReader["PopPort"].ToString()); try { if (cl.Authenticate()) { long mailCount = cl.GetTotalMessageCount(); for (int i = 1; i <= mailCount; i++) { this.SaveExtMail(cl.GetMessage(i), Username, dataReader["Email"].ToString()); } } } catch (Exception eX) { throw eX; } finally { cl.Close(); } } } } }
private void TestPopConn(string PopServer, string Uname, string Pwd, string Port, int OrderID) { long Count; //jmail.Message Msg=new jmail.Message(); //jmail.POP3 jpop = new jmail.POP3(); Pop3Client cl = new Pop3Client(PopServer); cl.UserName = Uname; cl.Password = Pwd; cl.Ssl = false; cl.Port = int.Parse(Port); try { //jpop.Connect(Uname,Pwd,PopServer,Int32.Parse(Port)); if (cl.Authenticate()) { //Count = jpop.Count; Count = cl.GetTotalMessageCount(); switch (OrderID) { case 1: this.lblResultRep1.Visible = true; this.lblResultRep1.Text = "测试成功,共有 " + Count.ToString() + " 封邮件"; break; case 2: this.lblResultRep2.Visible = true; this.lblResultRep2.Text = "测试成功,共有 " + Count.ToString() + " 封邮件"; break; case 3: this.lblResultRep3.Visible = true; this.lblResultRep3.Text = "测试成功,共有 " + Count.ToString() + " 封邮件"; break; default: break; } //jpop.Disconnect(); cl.Close(); } } catch (Exception e) { switch (OrderID) { case 1: this.lblResultRep1.Visible = true; this.lblResultRep1.Text = "未能连接到所指定的[接收邮件服务器],或输入了错误的[用户名]或[密码]!"; break; case 2: this.lblResultRep2.Visible = true; this.lblResultRep2.Text = "未能连接到所指定的[接收邮件服务器],或输入了错误的[用户名]或[密码]!"; break; case 3: this.lblResultRep3.Visible = true; this.lblResultRep3.Text = "未能连接到所指定的[接收邮件服务器],或输入了错误的[用户名]或[密码]!"; break; default: break; } } }