<servernames autodetect="true" autodetectIP="true"> <servername>test.com</servername> </servernames> <dnsserver> <servers> <!--Enter ip address of your DNS server, one IP address per server --> <server>127.0.0.1</server> <server>211.148.192.136</server> </servers> </dnsserver>
2錛夈佸惎鍔↗AMSES 鏈嶅姟鍣細
榪愯bin\run.bat錛岃緭鍑哄涓嬶細
Using PHOENIX_HOME: F:\dev\james-2.3.1 Using PHOENIX_TMPDIR: F:\dev\james-2.3.1\temp Using JAVA_HOME: D:\Program Files\Java\jdk1.5.0_16 Phoenix 4.2 James Mail Server 2.3.1 Remote Manager Service started plain:4555 POP3 Service started plain:110 SMTP Service started plain:25 NNTP Service started plain:119 FetchMail Disabled
JAMES Remote Administration Tool 2.3.1 Please enter your login and password Login id: root Password: root Welcome root. HELP for a list of commands adduser test test User test added quit Bye
4錛夊彂閫佷竴灝侀偖浠訛細
鍛戒護“telnet localhost 25”錛屼氦浜掕繃紼嬶細
220 kinkding-d1d01d SMTP Server (JAMES SMTP Server 2.3.1) ready Sat,25 Apr 200911:07:52 +0800 (CS ehlo test.com 250-kinkding-d1d01d Hello test.com (localhost [127.0.0.1]) 250-PIPELINING 250 ENHANCEDSTATUSCODES mail from:<foo@test.com> 2502.1.0 Sender <foo@test.com> OK rcpt to:<test@test.com> 2502.1.5 Recipient <test@test.com> OK data 354 Ok Send data ending with <CRLF>.<CRLF> subject:this is hello world email har ^_^ good haha . 2502.6.0 Message received quit 2212.0.0 kinkding-d1d01d Service closing transmission channel
5錛夊埌鏈嶅姟鍣ㄦ煡鐪嬮偖浠跺唴瀹癸細
F:\dev\james-2.3.1\apps\james\var\mail\inboxes\test>ls 4D61696C313234303632393039333837352D30.Repository.FileObjectStore 4D61696C313234303632393039333837352D30.Repository.FileStreamStore F:\dev\james-2.3.1\apps\james\var\mail\inboxes\test>more 4D61696C313234303632393039333837352D30.Repos*StreamStore Return-Path: <foo@test.com> Message-ID: <24964246.01240629093921.JavaMail.kinkding@kinkding-d1d01d> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Delivered-To: test@test.com Received: from localhost ([127.0.0.1]) by kinkding-d1d01d (JAMES SMTP Server 2.3.1) with SMTP ID 760 for <test@test.com>; Sat,25 Apr 200911:11:33 +0800 (CST) Date: Sat,25 Apr 200911:11:33 +0800 (CST) From: foo@test.com subject:this is hello world email har ^_^ good haha
/** *//** * 鎼滅儲閭歡 */ publicstaticvoid search(String subject, String from, boolean or) throws Exception { Session session = Session.getDefaultInstance(System.getProperties(), null); // session.setDebug(true); Store store = session.getStore(new URLName("imap://test:test@127.0.0.1")); store.connect(); Folder folder = store.getDefaultFolder(); // 鍦ㄦ敹浠剁涓悳绱?/span> folder = folder.getFolder("INBOX"); folder.open(Folder.READ_ONLY); List<SearchTerm> terms =new ArrayList<SearchTerm>(); // 鎸変富棰樻煡璇?/span> terms.add(new SubjectTerm(subject)); // 鎸夊彂浠朵漢鏌ヨ terms.add(new FromStringTerm(from)); // 涓涓皬鏃跺唴鐨勯偖浠?鎴戞湰鍦扮殑Megic Winmail閭歡鏈嶅姟鍣ㄦ煡涓嶅埌鍐呭錛?br />
// long time = System.currentTimeMillis(); // SentDateTerm dateTerm = new SentDateTerm(ComparisonTerm.GE, new Date( // time - 60 * 60 * 1000)); // terms.add(dateTerm); SearchTerm arrays[] =new SearchTerm[terms.size()]; terms.toArray(arrays); SearchTerm term = or ?new OrTerm(arrays) : new AndTerm(arrays); Message[] msgs = folder.search(term); System.out.println("FOUND "+ msgs.length +" MESSAGES"); for (int i =0; i < msgs.length; i++) { System.out.println("--------------------------"); System.out.println("MESSAGE #"+ (i +1) +":"); dumpEnvelope(msgs[i]); } } /** *//** * 鎵撳嵃閭歡鐨勫唴瀹?br />
* * @param m * @throws Exception */ publicstaticvoid dumpEnvelope(Message m) throws Exception { Address[] a; if ((a = m.getFrom()) !=null) { for (int j =0; j < a.length; j++) System.out.println("FROM: "+ a[j].toString()); } if ((a = m.getRecipients(Message.RecipientType.TO)) !=null) { for (int j =0; j < a.length; j++) { System.out.println("TO: "+ a[j].toString()); } } System.out.println("SUBJECT: "+ m.getSubject()); Date d = m.getSentDate(); System.out.println("SendDate: "+ (d !=null? d.toString() : "UNKNOWN")); } publicstaticvoid main(String[] args) { try{ search("subject", "test2@test.com", false); System.out.println("\n"); search("Fw: test", "test2@test.com", false); System.out.println("\n"); search("null", "test2@test.com", true); }catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
2銆佹祴璇曡緭鍑猴細
FOUND 0 MESSAGES FOUND 1 MESSAGES -------------------------- MESSAGE #1: FROM: test2 <test2@test.com> TO: test <test@test.com> SUBJECT: Fw: test SendDate: Tue Apr 2120:38:23 CST 2009 FOUND 2 MESSAGES -------------------------- MESSAGE #1: FROM: test2 <test2@test.com> TO: test <test@test.com> SUBJECT: 嫻嬭瘯閭歡 SendDate: Mon Apr 2021:42:53 CST 2009 -------------------------- MESSAGE #2: FROM: test2 <test2@test.com> TO: test <test@test.com> SUBJECT: Fw: test SendDate: Tue Apr 2120:38:23 CST 2009
3銆佺浉鍏寵鏄庯細
濡傛灉閲囩敤debug妯″紡鐨勮瘽錛屽彲浠ョ湅鍒拌皟鐢ㄥ拰鎼滅儲涓蹭箣闂寸殑瀵瑰簲鍏崇郴錛?br />
絎竴嬈★細SEARCH SUBJECT subject FROM test2@test.com ALL
絎簩嬈★細SEARCH SUBJECT "Fw: test" FROM test2@test.com ALL
絎笁嬈★細SEARCH OR SUBJECT null FROM test2@test.com ALL