| 发表于:2008-03-15 23:16:39 楼主 |
程序可以运行但是连不上服务器,编译时不报错 #include "stdafx.h" #include ".\pop3.h" #include "mapi.h" #define connection_check 1 #define user_check 2 #define password_check 3 #define stat_check 4 pop3::pop3(void) :m_nnum(0) ,m_strerr(_t("")) { m_server.create(); } pop3::~pop3(void) { m_server.close(); } bool pop3::connect(void) { return 0; } int pop3::getnumofmail(void) { return m_nnum; } bool pop3::disconnect(void) { return 0; } bool pop3::connect(cstring&host,cstring&user,cstring&pwd) { char buf[512]; if(!m_server.connect(host,110)) { m_strerr=_t("不能连接到邮件服务器"); return false; } else { if(checkresponse(connection_check)==false) return false; wsprintf(buf,"user%s\r\n",(lpcstr)user); m_server.send(buf,(int)strlen(buf)); if(checkresponse(user_check)==false) return false; wsprintf(buf,"pass%s\r\n",(lpcstr)user); m_server.send(buf,(int)strlen(buf)); if(checkresponse(password_check)==false) return false; return true; } } bool pop3::checkresponse(int resptype) { char buf[256]=""; m_server.receive(buf,sizeof(buf)); switch(resptype) { case connection_check: if(strnicmp(buf,"-err",4)==0) { m_strerr=_t("错误的连接!"); return false; } break; case user_check: if(strnicmp(buf,"-err",4)==0) { m_strerr=_t("错误的用户名!"); return false; } break; case password_check: if(strnicmp(buf,"-err",4)==0) { m_strerr=_t("错误的密码!"); return false; } break; case stat_check: if(strnicmp(buf,"-err",4)==0) { m_strerr=_t("命令错误!"); return false; } else { bool mailnum=true; for(char* p=buf;*p!='\0';p++) { if(*p=='\t' ¦ ¦*p=='\0') { if(mailnum==true) { m_nnum=atoi(p); mailnum=false; } else { m_nnum=atoi(p); return true; } } } } break; } return 0; } bool pop3::statistics(void) { char buf[512]; wsprintf(buf,"stat\r\n"); m_server.send(buf,(int)strlen(buf)); if(checkresponse(stat_check)==false) return false; else return true; } cstring pop3::geterrmsg(void) { return m_strerr; } 这是处理检测程序的类 void ccheckmaildlg::ontimer(uint nidevent) { // todo: 在此添加消息处理程序代码和/或调用默认值 pop3 popserver; killtimer(1); if(popserver.connect(m_server,m_user,m_pwd)==false) afxmessagebox(popserver.geterrmsg()); else if(popserver.statistics()==false) afxmessagebox(popserver.geterrmsg()); else { m_num=popserver.getnumofmail(); updatedata(false); settimer(1,m_nduration*1000,null); } cdialog::ontimer(nidevent); } 这是执行的函数 |
|
|
|
|