아래는 이메일을 받기위한 도구입니다. ! !
공개 클래스 {private mimemessage msg = private stringbuffer bodytext = private string hh : mm "; msg = msg;} public void setmsg (mimemessage msg) {this.msg = msg} / ** * 이메일 * @return * @throws messagingException * / public string getfrom (InternetAdDress ] address = (InternetAddress []) msg.getfrom (); ) (personal = "{personal =" "; 그리고 정보. 전달 된 매개 변수에 따라 "-> 수신자", "CC"-> CC 주소 "BCC"-> 클라이언트 주소 * @Param 유형 * @Throws MessagingException * @throws UnsupportedEncodingException */ public String getMailAddress (문자열 유형)는 메시징 지출을 던졌습니다. ) || addrtype.equals ( "bcc")) {if (addrtype.equals ( "to")) {address = (internetAddress []) msg.getRecipients (message.recipientType.to); "cc")) {address = (InternetAddress []) msg.getRecipients (wecipientType.cc); recipientType.bcc); Mail = ""} else {mailiTIME.DECODETEXT (Mail)} address [i]. decodetext (personal)} personal+"<"+mail+">; type! ");} return mailAddr;} / ** * 이메일 주제 받기 * @return * @Throws UnSupportedEncodingException * @throws messagingException * / public string getSubject () unsupportedEncodingException, messagingException {string groud =" "; .decodetext (msg.getSubject ()); ) MessagingException {date senddate = msg.getSentDate (); () {return bodytext.toString ()}; * @throws messagingException * @Throws IOException */ public void getMailContent (부품)는 messagingException {string contenttype = part.getContentType (); nameIndex! = -1) {conname = true} system.out.println ( "+contenttype); part.getContent (); /*"))) {multipart multipart = (multipart) part.getContent (); int count = multipart.getCount (); for (int i = 0; i <count; i ++) {getMailContent (multipart.getBodyPart (i)) } else if (part.ismimeType ( "message /rfc822") {getMailContent ((part) part.getContent ()); 그렇지 않으면 반환하십시오. @return * @throws messagingexception */ public boolean getReplySign (boolean replySign = false; ! = null) {replySign = true} returnsign} / ** *이 메시지의 메시지를받습니다. } / ** *이 메시지가 읽히지 않으면 거짓을 반환합니다. = FAGLS FLAGS = getFlags (); i = 0; i <flag.length; i ++) {if (flag [i] == flags.flag.seen) {isnew = true.out.println ( "Seen Message ......"); break;}} return isnew} / ** * 첨부 파트가 포함되어 있는지 * @throws messagingexception * / public boolean iscontainattch (부품). false; int i = 0; i <count; i ++) {bodypart bodypart.getBodyPart (i); | dispostion.equals (part.inline)) {flag = true} else (bodypart.ismimeType ( "multipart/*")) {flag = iscontainattch (bodypart); if (contype.tolowercase (). indexof ( "appliact") {flag = true} if (contype.tolowercase ( "name") {flag = true; }}}} else if (part.ismimeType ( "message /rfc822")) {flag = iscontainattch ((part) part.getContent ()); @Throws MessagingException *@throws ioexception */ public void seaittchment (part part)는 messagingException, ioException {part.ismimeType ( "multipart/ *"); (); int = 0; i <mp. getCount (); dispostion.equals (part.attachment) || dispostion.equals (part.inline))) {filename = parart.getfilename (); = mimeUtility.decodetext (filename)} savefile (filename, mpart .getInputStream ()); if (filename! = null && (filename.tolowercase (). indexof ( "gb2312")) {filename = mimeutility.decodetext (filename); }}} else if (part.ismimeType ( "message/rfc822")) {seaittchment ((part) part.getContent ())/*** 첨부를 저장하기 위해 주소를 가져옵니다. getSaveattchpath () {return seaittchpath} /*** 첨부를 저장하기 위해 주소를 설정하십시오 dateformate */ public void setDateFormate (String DateFormate) {this.dateformate = dateformate}/ * * * @param filename * @param inputStream * @throws ioxception */ private void savefile (string filename, inputstream inputstream). IoException {string.getProperty ( "os.name"); .indexof ( "win")! = -1) {sepatror = "//"; {sepatror = "/"; "/temp"; null; bufferedputstream {bos = new fileoutputstream (intperedinputstream); .write (c);} catch (filenotfoundexception e) {// exception e) {// toda auto-auto-autocection e); .printstacktrace ()} 마지막으로 {bos.close (); ------------ 시작 ------- ------------------------ "); System.out.println ("메시지 " +i+"+getSubject ());"+getfrom ()); ()); boolean 플래그 = iscontainattch (part); "+i+"iscontainattch : "+flag.out.println; GetMailContent (part). part);} system.out.println ( "----------------------- --------------- ");}}
이메일 수신 및 도구 사용법을 작성하는 방법에는 여러 가지가 있습니다! :
인터넷에서 다른 코드를 많이 읽었습니다. Pop3server는 Pop.mail.163.com이지만 사용자 이름@... com 또는 사용자 이름을 사용하지 못했습니다.
들어오는 이메일이 163 사서함 인 경우 먼저 163 사서함에 로그인하여 POP3 서비스를 활성화해야합니다. 아직 다른 이메일 주소를 모르겠습니다.
public static void main (string [] args)은 {// pop3 서버에 연결된 pop3 서버의 호스트 이름, 프로토콜, 사용자 이름 및 비밀번호를 던졌습니다. pop3server = "pop.163.com"; pop3 "; String user ="username "; String pwd ="password "; // 특정 연결 정보 속성이있는 속성 객체 생성 Properties = new Properties (); propss.setProperty ("mail.store.protocol ", 프로토콜); props.setProperty ( "mail .pop3.host", pop3server); POP3 서버 스토어에 연결하고 SESTION.CONNECT (POP3SERVER, USER, PWD); getfolder ( "Inbox"); = 0; rm = new recivemail (mimemessage) rm.recive; .닫다(); }