KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > mail > MailMessageTest


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

17
18 package org.apache.tools.mail;
19
20 import java.io.BufferedReader JavaDoc;
21 import java.io.BufferedWriter JavaDoc;
22 import java.io.ByteArrayOutputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStreamReader JavaDoc;
25 import java.io.OutputStreamWriter JavaDoc;
26 import java.io.PrintStream JavaDoc;
27 import java.net.InetAddress JavaDoc;
28 import java.net.Socket JavaDoc;
29 import java.net.ServerSocket JavaDoc;
30 import java.util.Enumeration JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import org.apache.tools.mail.MailMessage;
34
35 import junit.framework.TestCase;
36
37 /**
38  * JUnit 3 testcases for org.apache.tools.mail.MailMessage.
39  *
40  * @since Ant 1.6
41  */

42 public class MailMessageTest extends TestCase {
43
44     // 27224 = magic (a random port which is unlikely to be in use)
45
private static int TEST_PORT = 27224;
46
47     private String JavaDoc local = null;
48
49     public MailMessageTest(String JavaDoc name) {
50         super(name);
51     }
52
53     public void setUp() {
54         try {
55             local = InetAddress.getLocalHost().getHostName();
56         } catch (java.net.UnknownHostException JavaDoc uhe) {
57             // ignore
58
}
59     }
60
61     /**
62      * Test an example that is similar to the one given in the API
63      * If this testcase takes >90s to complete, it is very likely that
64      * the two threads are blocked waiting for each other and Thread.join()
65      * timed out.
66      */

67     public void testAPIExample() {
68
69         ServerThread testMailServer = new ServerThread();
70         Thread JavaDoc server = new Thread JavaDoc(testMailServer);
71         server.start();
72
73         ClientThread testMailClient = new ClientThread();
74
75         testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");
76         testMailClient.to("to@you.com");
77         testMailClient.cc("cc1@you.com");
78         testMailClient.cc("cc2@you.com");
79         testMailClient.bcc("bcc@you.com");
80         testMailClient.setSubject("Test subject");
81         testMailClient.setMessage( "test line 1\n" +
82             "test line 2" );
83
84         Thread JavaDoc client = new Thread JavaDoc(testMailClient);
85         client.start();
86
87         try {
88             server.join(60 * 1000); // 60s
89
client.join(30 * 1000); // a further 30s
90
} catch (InterruptedException JavaDoc ie ) {
91             fail( "InterruptedException: " + ie );
92         }
93
94         String JavaDoc result = testMailServer.getResult();
95         String JavaDoc expectedResult = "220 test SMTP EmailTaskTest\r\n" +
96         "HELO " + local + "\r\n" +
97         "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +
98         "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +
99         "250\r\n" +
100         "RCPT TO: <to@you.com>\r\n" +
101         "250\r\n" +
102         "RCPT TO: <cc1@you.com>\r\n" +
103         "250\r\n" +
104         "RCPT TO: <cc2@you.com>\r\n" +
105         "250\r\n" +
106         "RCPT TO: <bcc@you.com>\r\n" +
107         "250\r\n" +
108         "DATA\r\n" +
109         "354\r\n" +
110         "Subject: Test subject\r\n" +
111         "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +
112         "To: to@you.com\r\n" +
113         "Cc: cc1@you.com, cc2@you.com\r\n" +
114         "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +
115         "\r\n" +
116         "test line 1\r\n" +
117         "test line 2\r\n" +
118         "\r\n" +
119         ".\r\n" +
120         "250\r\n" +
121         "QUIT\r\n" +
122         "221\r\n";
123         for (int icounter = 0; icounter<expectedResult.length(); icounter++) {
124             if (icounter < result.length()) {
125                 if (expectedResult.charAt(icounter) != result.charAt(icounter)) {
126                     System.out.println("posit " + icounter + " expected "
127                         + expectedResult.charAt(icounter)
128                     + " result " + result.charAt(icounter));
129                 }
130             }
131         }
132         if (expectedResult.length()>result.length()) {
133             System.out.println("excedent of expected result "
134                 + expectedResult.substring(result.length()));
135         }
136         if (expectedResult.length()<result.length()) {
137             System.out.println("excedent of result "
138                 + result.substring(expectedResult.length()));
139         }
140         assertEquals(expectedResult.length(), result.length());
141         assertEquals(expectedResult, result); // order of headers cannot be guaranteed
142
if (testMailClient.isFailed()) {
143             fail(testMailClient.getFailMessage());
144         }
145     }
146
147     /**
148      * Test a MailMessage with no cc or bcc lines
149      */

150     public void testToOnly() {
151         ServerThread testMailServer = new ServerThread();
152         Thread JavaDoc server = new Thread JavaDoc(testMailServer);
153         server.start();
154
155         ClientThread testMailClient = new ClientThread();
156
157         testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");
158         testMailClient.to("to@you.com");
159         testMailClient.setSubject("Test subject");
160         testMailClient.setMessage( "test line 1\n" +
161             "test line 2" );
162
163         Thread JavaDoc client = new Thread JavaDoc(testMailClient);
164         client.start();
165
166         try {
167             server.join(60 * 1000); // 60s
168
client.join(30 * 1000); // a further 30s
169
} catch (InterruptedException JavaDoc ie ) {
170             fail("InterruptedException: " + ie);
171         }
172
173         String JavaDoc result = testMailServer.getResult();
174         String JavaDoc expectedResult = "220 test SMTP EmailTaskTest\r\n" +
175         "HELO " + local + "\r\n" +
176         "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +
177         "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +
178         "250\r\n" +
179         "RCPT TO: <to@you.com>\r\n" +
180         "250\r\n" +
181         "DATA\r\n" +
182         "354\r\n" +
183         "Subject: Test subject\r\n" +
184             "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +
185             "To: to@you.com\r\n" +
186         "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +
187         "\r\n" +
188         "test line 1\r\n" +
189         "test line 2\r\n" +
190         "\r\n" +
191         ".\r\n" +
192         "250\r\n" +
193         "QUIT\r\n" +
194         "221\r\n";
195         assertEquals(expectedResult.length(), result.length());
196         assertEquals(expectedResult, result); // order of headers cannot be guaranteed
197
if (testMailClient.isFailed()) {
198             fail(testMailClient.getFailMessage());
199         }
200     }
201
202
203     /**
204      * Test a MailMessage with no to or bcc lines
205      */

206     public void testCcOnly() {
207         ServerThread testMailServer = new ServerThread();
208         Thread JavaDoc server = new Thread JavaDoc(testMailServer);
209         server.start();
210
211         ClientThread testMailClient = new ClientThread();
212
213         testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");
214         testMailClient.cc("cc@you.com");
215         testMailClient.setSubject("Test subject");
216         testMailClient.setMessage( "test line 1\n" +
217             "test line 2" );
218
219         Thread JavaDoc client = new Thread JavaDoc(testMailClient);
220         client.start();
221
222         try {
223             server.join(60 * 1000); // 60s
224
client.join(30 * 1000); // a further 30s
225
} catch (InterruptedException JavaDoc ie ) {
226             fail( "InterruptedException: " + ie );
227         }
228
229         String JavaDoc result = testMailServer.getResult();
230         String JavaDoc expectedResult = "220 test SMTP EmailTaskTest\r\n" +
231         "HELO " + local + "\r\n" +
232         "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +
233         "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +
234         "250\r\n" +
235         "RCPT TO: <cc@you.com>\r\n" +
236         "250\r\n" +
237         "DATA\r\n" +
238         "354\r\n" +
239         "Subject: Test subject\r\n" +
240             "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +
241             "Cc: cc@you.com\r\n" +
242         "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +
243         "\r\n" +
244         "test line 1\r\n" +
245         "test line 2\r\n" +
246         "\r\n" +
247         ".\r\n" +
248         "250\r\n" +
249         "QUIT\r\n" +
250         "221\r\n";
251         assertEquals(expectedResult.length(), result.length());
252         assertEquals(expectedResult, result);
253         if (testMailClient.isFailed()) {
254             fail(testMailClient.getFailMessage());
255         }
256     }
257
258
259     /**
260      * Test a MailMessage with no to or cc lines
261      */

262     public void testBccOnly() {
263         ServerThread testMailServer = new ServerThread();
264         Thread JavaDoc server = new Thread JavaDoc(testMailServer);
265         server.start();
266
267         ClientThread testMailClient = new ClientThread();
268
269         testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");
270         testMailClient.bcc("bcc@you.com");
271         testMailClient.setSubject("Test subject");
272         testMailClient.setMessage( "test line 1\n" +
273             "test line 2" );
274
275         Thread JavaDoc client = new Thread JavaDoc(testMailClient);
276         client.start();
277
278         try {
279             server.join(60 * 1000); // 60s
280
client.join(30 * 1000); // a further 30s
281
} catch (InterruptedException JavaDoc ie ) {
282             fail( "InterruptedException: " + ie );
283         }
284
285         String JavaDoc result = testMailServer.getResult();
286         String JavaDoc expectedResult = "220 test SMTP EmailTaskTest\r\n" +
287         "HELO " + local + "\r\n" +
288         "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +
289         "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +
290         "250\r\n" +
291         "RCPT TO: <bcc@you.com>\r\n" +
292         "250\r\n" +
293         "DATA\r\n" +
294         "354\r\n" +
295         "Subject: Test subject\r\n" +
296         "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +
297         "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +
298         "\r\n" +
299         "test line 1\r\n" +
300         "test line 2\r\n" +
301         "\r\n" +
302         ".\r\n" +
303         "250\r\n" +
304         "QUIT\r\n" +
305         "221\r\n";
306         assertEquals( expectedResult.length(), result.length() );
307         assertEquals( expectedResult, result );
308         if ( testMailClient.isFailed() ) {
309             fail( testMailClient.getFailMessage() );
310         }
311     }
312
313
314     /**
315      * Test a MailMessage with no subject line
316      * Subject is an optional field (RFC 822 s4.1)
317      */

318     public void testNoSubject() {
319         ServerThread testMailServer = new ServerThread();
320         Thread JavaDoc server = new Thread JavaDoc(testMailServer);
321         server.start();
322
323         ClientThread testMailClient = new ClientThread();
324
325         testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");
326         testMailClient.to("to@you.com");
327         testMailClient.setMessage( "test line 1\n" +
328             "test line 2" );
329
330         Thread JavaDoc client = new Thread JavaDoc(testMailClient);
331         client.start();
332
333         try {
334             server.join(60 * 1000); // 60s
335
client.join(30 * 1000); // a further 30s
336
} catch (InterruptedException JavaDoc ie ) {
337             fail( "InterruptedException: " + ie );
338         }
339
340         String JavaDoc result = testMailServer.getResult();
341         String JavaDoc expectedResult = "220 test SMTP EmailTaskTest\r\n" +
342         "HELO " + local + "\r\n" +
343         "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +
344         "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +
345         "250\r\n" +
346         "RCPT TO: <to@you.com>\r\n" +
347         "250\r\n" +
348         "DATA\r\n" +
349         "354\r\n" +
350         "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +
351             "To: to@you.com\r\n" +
352         "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +
353         "\r\n" +
354         "test line 1\r\n" +
355         "test line 2\r\n" +
356         "\r\n" +
357         ".\r\n" +
358         "250\r\n" +
359         "QUIT\r\n" +
360         "221\r\n";
361         assertEquals( expectedResult.length(), result.length() );
362         assertEquals( expectedResult, result );
363         if ( testMailClient.isFailed() ) {
364             fail( testMailClient.getFailMessage() );
365         }
366     }
367
368
369     /**
370      * Test a MailMessage with empty body message
371      */

372     public void testEmptyBody() {
373         ServerThread testMailServer = new ServerThread();
374         Thread JavaDoc server = new Thread JavaDoc(testMailServer);
375         server.start();
376
377         ClientThread testMailClient = new ClientThread();
378
379         testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");
380         testMailClient.to("to@you.com");
381         testMailClient.setSubject("Test subject");
382         testMailClient.setMessage("");
383
384         Thread JavaDoc client = new Thread JavaDoc(testMailClient);
385         client.start();
386
387         try {
388             server.join(60 * 1000); // 60s
389
client.join(30 * 1000); // a further 30s
390
} catch (InterruptedException JavaDoc ie ) {
391             fail( "InterruptedException: " + ie );
392         }
393
394         String JavaDoc result = testMailServer.getResult();
395         String JavaDoc expectedResult = "220 test SMTP EmailTaskTest\r\n" +
396         "HELO " + local + "\r\n" +
397         "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +
398         "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +
399         "250\r\n" +
400         "RCPT TO: <to@you.com>\r\n" +
401         "250\r\n" +
402         "DATA\r\n" +
403         "354\r\n" +
404         "Subject: Test subject\r\n" +
405             "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +
406             "To: to@you.com\r\n" +
407         "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +
408         "\r\n" +
409         "\r\n" +
410         "\r\n" +
411         ".\r\n" +
412         "250\r\n" +
413         "QUIT\r\n" +
414         "221\r\n";
415         assertEquals(expectedResult.length(), result.length());
416         assertEquals(expectedResult, result);
417         if (testMailClient.isFailed()) {
418             fail(testMailClient.getFailMessage());
419         }
420     }
421
422
423     /**
424      * Test a MailMessage with US-ASCII character set
425      * The next four testcase can be kinda hard to debug as Ant will often
426      * print the junit failure in US-ASCII.
427      */

428     public void testAsciiCharset() {
429
430         ServerThread testMailServer = new ServerThread();
431         Thread JavaDoc server = new Thread JavaDoc(testMailServer);
432         server.start();
433
434         ClientThread testMailClient = new ClientThread();
435
436         testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");
437         testMailClient.to("Ceki G\u00fclc\u00fc <abuse@mail-abuse.org>");
438         testMailClient.setSubject("Test subject");
439         testMailClient.setMessage("");
440
441         Thread JavaDoc client = new Thread JavaDoc(testMailClient);
442         client.start();
443
444         try {
445             server.join(60 * 1000); // 60s
446
client.join(30 * 1000); // a further 30s
447
} catch (InterruptedException JavaDoc ie ) {
448             fail("InterruptedException: " + ie);
449         }
450
451         String JavaDoc result = testMailServer.getResult();
452         String JavaDoc expectedResult = "220 test SMTP EmailTaskTest\r\n" +
453         "HELO " + local + "\r\n" +
454         "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +
455         "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +
456         "250\r\n" +
457         "RCPT TO: <abuse@mail-abuse.org>\r\n" +
458         "250\r\n" +
459         "DATA\r\n" +
460         "354\r\n" +
461         "Subject: Test subject\r\n" +
462             "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +
463             "To: Ceki G\u00fclc\u00fc <abuse@mail-abuse.org>\r\n" +
464         "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +
465         "\r\n" +
466         "\r\n" +
467         "\r\n" +
468         ".\r\n" +
469         "250\r\n" +
470         "QUIT\r\n" +
471         "221\r\n";
472         ByteArrayOutputStream JavaDoc baos1 = new ByteArrayOutputStream JavaDoc();
473         ByteArrayOutputStream JavaDoc baos2 = new ByteArrayOutputStream JavaDoc();
474         PrintStream JavaDoc bos1 = new PrintStream JavaDoc(baos1, true);
475         PrintStream JavaDoc bos2 = new PrintStream JavaDoc(baos2, true);
476
477         bos1.print(expectedResult);
478         bos2.print(result);
479
480         assertEquals( "expected message length != actual message length "
481             + "in testAsciiCharset()", expectedResult.length(), result.length() );
482         assertEquals( "baos1 and baos2 should be the same in testAsciiCharset()",
483             baos1.toString(), baos2.toString() ); // order of headers cannot be guaranteed
484
if (testMailClient.isFailed()) {
485             fail(testMailClient.getFailMessage());
486         }
487     }
488
489
490
491
492     /**
493      * A private test class that pretends to be a mail transfer agent
494      */

495     private class ServerThread implements Runnable JavaDoc {
496
497         private StringBuffer JavaDoc sb = null;
498         private boolean loop = false;
499         ServerSocket JavaDoc ssock = null;
500         Socket JavaDoc sock = null;
501         BufferedWriter JavaDoc out = null;
502         BufferedReader JavaDoc in = null;
503         private boolean data = false; // state engine: false=envelope, true=message
504

505         public void run() {
506
507             try {
508                 ssock = new ServerSocket JavaDoc(TEST_PORT);
509                 sock = ssock.accept(); // wait for connection
510
in = new BufferedReader JavaDoc( new InputStreamReader JavaDoc(
511                     sock.getInputStream()) );
512                 out = new BufferedWriter JavaDoc( new OutputStreamWriter JavaDoc(
513                     sock.getOutputStream() ) );
514                 sb = new StringBuffer JavaDoc();
515                 send( "220 test SMTP EmailTaskTest\r\n" );
516                 loop = true;
517                 while ( loop ) {
518                     String JavaDoc response = in.readLine();
519                     if ( response == null ) {
520                         loop = false;
521                         break;
522                     }
523                     sb.append( response + "\r\n" );
524
525                     if ( !data && response.startsWith( "HELO" ) ) {
526                         send( "250 " + local + " Hello " + local + " " +
527                         "[127.0.0.1], pleased to meet you\r\n" );
528                     } else if ( !data && response.startsWith("MAIL") ) {
529                         send( "250\r\n" );
530                     } else if ( !data && response.startsWith("RCPT")) {
531                         send( "250\r\n" );
532                     } else if (!data && response.startsWith("DATA")) {
533                         send( "354\r\n" );
534                         data = true;
535                     } else if (data && response.equals(".") ) {
536                         send( "250\r\n" );
537                         data = false;
538                     } else if (!data && response.startsWith("QUIT")) {
539                         send( "221\r\n" );
540                         loop = false;
541                     } else if (!data) {
542                         //throw new IllegalStateException("Command unrecognized: "
543
// + response);
544
send( "500 5.5.1 Command unrecognized: \"" +
545                             response + "\"\r\n" );
546                         loop = false;
547                     } else {
548                         // sb.append( response + "\r\n" );
549
}
550
551                 } // while
552
} catch (IOException JavaDoc ioe) {
553                 fail();
554             } finally {
555                 disconnect();
556             }
557         }
558
559         private void send(String JavaDoc retmsg) throws IOException JavaDoc {
560             out.write( retmsg );
561             out.flush();
562             sb.append( retmsg );
563         }
564
565         private void disconnect() {
566             if (out != null) {
567                 try {
568                     out.flush();
569                     out.close();
570                     out = null;
571                 } catch (IOException JavaDoc e) {
572                     // ignore
573
}
574             }
575             if (in != null) {
576                 try {
577                     in.close();
578                     in = null;
579                 } catch (IOException JavaDoc e) {
580                     // ignore
581
}
582             }
583             if (sock != null) {
584                 try {
585                     sock.close();
586                     sock = null;
587                 } catch (IOException JavaDoc e) {
588                     // ignore
589
}
590             }
591             if (ssock != null) {
592                 try {
593                     ssock.close();
594                     ssock = null;
595                 } catch (IOException JavaDoc e) {
596                     // ignore
597
}
598             }
599         }
600
601         public synchronized String JavaDoc getResult() {
602             loop = false;
603             return sb.toString();
604         }
605
606     }
607
608     /**
609      * A private test class that wraps MailMessage
610      */

611     private class ClientThread implements Runnable JavaDoc {
612
613         private MailMessage msg;
614         private boolean fail = false;
615         private String JavaDoc failMessage = null;
616
617         protected String JavaDoc from = null;
618         protected String JavaDoc subject = null;
619         protected String JavaDoc message = null;
620
621         protected Vector JavaDoc replyToList = new Vector JavaDoc();
622         protected Vector JavaDoc toList = new Vector JavaDoc();
623         protected Vector JavaDoc ccList = new Vector JavaDoc();
624         protected Vector JavaDoc bccList = new Vector JavaDoc();
625
626
627         public void run() {
628             for (int i = 9; i > 0; i--) {
629                 try {
630                     msg = new MailMessage("localhost", TEST_PORT);
631                 } catch (java.net.ConnectException JavaDoc ce) {
632                     try {
633                         Thread.sleep(10 * 1000);
634                     } catch (InterruptedException JavaDoc ie) {
635                         // ignore
636
}
637                 } catch (IOException JavaDoc ioe) {
638                     fail = true;
639                     failMessage = "IOException: " + ioe;
640                     return;
641                 }
642                 if (msg != null) {
643                     break;
644                 }
645             }
646
647             if (msg == null) {
648                 fail = true;
649                 failMessage = "java.net.ConnectException: Connection refused";
650                 return;
651             }
652
653             try {
654                 msg.from(from);
655
656                 Enumeration JavaDoc e;
657
658                 e = replyToList.elements();
659                 while (e.hasMoreElements()) {
660                     msg.replyto(e.nextElement().toString());
661                 }
662
663                 e = toList.elements();
664                 while (e.hasMoreElements()) {
665                     msg.to(e.nextElement().toString());
666                 }
667
668                 e = ccList.elements();
669                 while (e.hasMoreElements()) {
670                     msg.cc(e.nextElement().toString());
671                 }
672
673                 e = bccList.elements();
674                 while (e.hasMoreElements()) {
675                     msg.bcc(e.nextElement().toString());
676                 }
677
678                 if (subject != null) {
679                     msg.setSubject(subject);
680                 }
681
682                 if (message != null ) {
683                     PrintStream JavaDoc out = msg.getPrintStream();
684                     out.println( message );
685                 }
686
687                 msg.sendAndClose();
688             } catch (IOException JavaDoc ioe) {
689                 fail = true;
690                 failMessage = "IOException: " + ioe;
691                 return;
692             }
693         }
694
695         public boolean isFailed() {
696             return fail;
697         }
698
699         public String JavaDoc getFailMessage() {
700             return failMessage;
701         }
702
703         public void replyTo(String JavaDoc replyTo) {
704             replyToList.add(replyTo);
705         }
706
707         public void to(String JavaDoc to) {
708             toList.add(to);
709         }
710
711         public void cc(String JavaDoc cc) {
712             ccList.add(cc);
713         }
714
715         public void bcc(String JavaDoc bcc) {
716             bccList.add(bcc);
717         }
718
719         public void setSubject(String JavaDoc subject) {
720             this.subject = subject;
721         }
722
723         public void from(String JavaDoc from) {
724             this.from = from;
725         }
726
727         public void setMessage(String JavaDoc message) {
728             this.message = message;
729         }
730
731     }
732
733 }
734
Popular Tags