KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > imapserver > InitialMail


1 /***********************************************************************
2  * Copyright (c) 2000-2004 The Apache Software Foundation. *
3  * All rights reserved. *
4  * ------------------------------------------------------------------- *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you *
6  * may not use this file except in compliance with the License. You *
7  * may obtain a copy of the License at: *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
14  * implied. See the License for the specific language governing *
15  * permissions and limitations under the License. *
16  ***********************************************************************/

17
18 package org.apache.james.imapserver;
19
20 import junit.framework.TestCase;
21
22 import javax.mail.internet.InternetAddress JavaDoc;
23 import javax.mail.internet.MimeMessage JavaDoc;
24 import javax.mail.Message JavaDoc;
25 import javax.mail.Session JavaDoc;
26 import javax.mail.Transport JavaDoc;
27 import java.util.Properties JavaDoc;
28
29 public final class InitialMail extends TestCase
30         implements IMAPTest
31 {
32     private Session JavaDoc _session;
33     private InternetAddress JavaDoc _fromAddress;
34     private InternetAddress JavaDoc _toAddress;
35
36     public InitialMail( String JavaDoc name )
37     {
38         super( name );
39     }
40
41     protected void setUp() throws Exception JavaDoc
42     {
43         super.setUp();
44         Properties JavaDoc props = new Properties JavaDoc();
45         props.setProperty("mail.debug","true");
46         _session = Session.getDefaultInstance( props );
47
48         _fromAddress = new InternetAddress JavaDoc( FROM_ADDRESS );
49         _toAddress = new InternetAddress JavaDoc( TO_ADDRESS );
50     }
51
52     public void testSendInitialMessages() throws Exception JavaDoc
53     {
54         sendMessage( "Message 1", "This is the first message." );
55         sendMessage( "Message 2", "This is the second message." );
56         sendMessage( "Message 3", "This is the third message." );
57         sendMessage( "Message 4", "This is the fourth message." );
58     }
59
60     private void sendMessage( String JavaDoc subject, String JavaDoc body )
61             throws Exception JavaDoc
62     {
63         MimeMessage JavaDoc msg = new MimeMessage JavaDoc(_session);
64         msg.setFrom( _fromAddress );
65         msg.addRecipient(Message.RecipientType.TO, _toAddress );
66         msg.setSubject( subject );
67         msg.setContent( body, "text/plain" );
68
69         Transport.send( msg );
70         System.out.println( "Sending message: " + subject );
71         
72         Thread.sleep( 1000 );
73     }
74 }
75
Popular Tags