1 17 18 package org.apache.james.imapserver; 19 20 import junit.framework.TestCase; 21 22 import javax.mail.internet.InternetAddress ; 23 import javax.mail.internet.MimeMessage ; 24 import javax.mail.Message ; 25 import javax.mail.Session ; 26 import javax.mail.Transport ; 27 import java.util.Properties ; 28 29 public final class InitialMail extends TestCase 30 implements IMAPTest 31 { 32 private Session _session; 33 private InternetAddress _fromAddress; 34 private InternetAddress _toAddress; 35 36 public InitialMail( String name ) 37 { 38 super( name ); 39 } 40 41 protected void setUp() throws Exception 42 { 43 super.setUp(); 44 Properties props = new Properties (); 45 props.setProperty("mail.debug","true"); 46 _session = Session.getDefaultInstance( props ); 47 48 _fromAddress = new InternetAddress ( FROM_ADDRESS ); 49 _toAddress = new InternetAddress ( TO_ADDRESS ); 50 } 51 52 public void testSendInitialMessages() throws Exception 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 subject, String body ) 61 throws Exception 62 { 63 MimeMessage msg = new MimeMessage (_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 |