1 package org.apache.commons.net.smtp;
2
3 /* ====================================================================
4 * The Apache Software License, Version 1.1
5 *
6 * Copyright (c) 2001 The Apache Software Foundation. All rights
7 * reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. The end-user documentation included with the redistribution,
22 * if any, must include the following acknowledgment:
23 * "This product includes software developed by the
24 * Apache Software Foundation (http://www.apache.org/)."
25 * Alternately, this acknowledgment may appear in the software itself,
26 * if and wherever such third-party acknowledgments normally appear.
27 *
28 * 4. The names "Apache" and "Apache Software Foundation" and
29 * "Apache Commons" must not be used to endorse or promote products
30 * derived from this software without prior written permission. For
31 * written permission, please contact apache@apache.org.
32 *
33 * 5. Products derived from this software may not be called "Apache",
34 * nor may "Apache" appear in their name, without
35 * prior written permission of the Apache Software Foundation.
36 *
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This software consists of voluntary contributions made by many
52 * individuals on behalf of the Apache Software Foundation. For more
53 * information on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57 import java.io.BufferedReader;
58 import java.io.BufferedWriter;
59 import java.io.IOException;
60 import java.io.InputStreamReader;
61 import java.io.OutputStreamWriter;
62 import java.util.Enumeration;
63 import java.util.Vector;
64 import org.apache.commons.net.MalformedServerReplyException;
65 import org.apache.commons.net.ProtocolCommandListener;
66 import org.apache.commons.net.ProtocolCommandSupport;
67 import org.apache.commons.net.SocketClient;
68
69 /****
70 * SMTP provides the basic the functionality necessary to implement your
71 * own SMTP client. To derive the full benefits of the SMTP class requires
72 * some knowledge of the FTP protocol defined in RFC 821. However, there
73 * is no reason why you should have to use the SMTP class. The
74 * <a href="org.apache.commons.net.smtp.SMTPClient.html"> SMTPClient </a> class,
75 * derived from SMTP,
76 * implements all the functionality required of an SMTP client. The
77 * SMTP class is made public to provide access to various SMTP constants
78 * and to make it easier for adventurous programmers (or those with
79 * special needs) to interact with the SMTP protocol and implement their
80 * own clients. A set of methods with names corresponding to the SMTP
81 * command names are provided to facilitate this interaction.
82 * <p>
83 * You should keep in mind that the SMTP server may choose to prematurely
84 * close a connection for various reasons. The SMTP class will detect a
85 * premature SMTP server connection closing when it receives a
86 * <a href="org.apache.commons.net.smtp.SMTPReply.html#SERVICE_NOT_AVAILABLE">
87 * SMTPReply.SERVICE_NOT_AVAILABLE </a> response to a command.
88 * When that occurs, the SMTP class method encountering that reply will throw
89 * an <a href="org.apache.commons.net.smtp.SMTPConnectionClosedException.html">
90 * SMTPConnectionClosedException </a>.
91 * <code>SMTPConectionClosedException</code>
92 * is a subclass of <code> IOException </code> and therefore need not be
93 * caught separately, but if you are going to catch it separately, its
94 * catch block must appear before the more general <code> IOException </code>
95 * catch block. When you encounter an
96 * <a href="org.apache.commons.net.smtp.SMTPConnectionClosedException.html">
97 * SMTPConnectionClosedException </a>, you must disconnect the connection with
98 * <a href="org.apache.commons.net.SocketClient.html#disconnect"> disconnect() </a>
99 * to properly clean up the system resources used by SMTP. Before
100 * disconnecting, you may check the
101 * last reply code and text with
102 * <a href="#getReplyCode"> getReplyCode </a>,
103 * <a href="#getReplyString"> getReplyString </a>,
104 * and <a href="#getReplyStrings"> getReplyStrings</a>.
105 * <p>
106 * Rather than list it separately for each method, we mention here that
107 * every method communicating with the server and throwing an IOException
108 * can also throw a
109 * <a href="org.apache.commons.net.MalformedServerReplyException.html">
110 * MalformedServerReplyException </a>, which is a subclass
111 * of IOException. A MalformedServerReplyException will be thrown when
112 * the reply received from the server deviates enough from the protocol
113 * specification that it cannot be interpreted in a useful manner despite
114 * attempts to be as lenient as possible.
115 * <p>
116 * <p>
117 * @author Daniel F. Savarese
118 * @see SMTPClient
119 * @see SMTPConnectionClosedException
120 * @see org.apache.commons.net.MalformedServerReplyException
121 ***/
122
123 public class SMTP extends SocketClient
124 {
125 /**** The default SMTP port (25). ***/
126 public static final int DEFAULT_PORT = 25;
127
128 private StringBuffer __commandBuffer;
129
130 BufferedReader _reader;
131 BufferedWriter _writer;
132 int _replyCode;
133 Vector _replyLines;
134 boolean _newReplyString;
135 String _replyString;
136
137 /****
138 * A ProtocolCommandSupport object used to manage the registering of
139 * ProtocolCommandListeners and te firing of ProtocolCommandEvents.
140 ***/
141 protected ProtocolCommandSupport _commandSupport_;
142
143 /****
144 * The default SMTP constructor. Sets the default port to
145 * <code>DEFAULT_PORT</code> and initializes internal data structures
146 * for saving SMTP reply information.
147 ***/
148 public SMTP()
149 {
150 setDefaultPort(DEFAULT_PORT);
151 __commandBuffer = new StringBuffer();
152 _replyLines = new Vector();
153 _newReplyString = false;
154 _replyString = null;
155 _commandSupport_ = new ProtocolCommandSupport(this);
156 }
157
158 private int __sendCommand(String command, String args, boolean includeSpace)
159 throws IOException
160 {
161 String message;
162
163 __commandBuffer.setLength(0);
164 __commandBuffer.append(command);
165
166 if (args != null)
167 {
168 if (includeSpace)
169 __commandBuffer.append(' ');
170 __commandBuffer.append(args);
171 }
172
173 __commandBuffer.append(SocketClient.NETASCII_EOL);
174
175 _writer.write(message = __commandBuffer.toString());
176 _writer.flush();
177
178 if (_commandSupport_.getListenerCount() > 0)
179 _commandSupport_.fireCommandSent(command, message);
180
181 __getReply();
182 return _replyCode;
183 }
184
185 private int __sendCommand(int command, String args, boolean includeSpace)
186 throws IOException
187 {
188 return __sendCommand(SMTPCommand._commands[command], args, includeSpace);
189 }
190
191 private void __getReply() throws IOException
192 {
193 int length;
194 String line, code;
195
196 _newReplyString = true;
197 _replyLines.setSize(0);
198
199 line = _reader.readLine();
200
201 if (line == null)
202 throw new SMTPConnectionClosedException(
203 "Connection closed without indication.");
204
205 // In case we run into an anomaly we don't want fatal index exceptions
206 // to be thrown.
207 length = line.length();
208 if (length < 3)
209 throw new MalformedServerReplyException(
210 "Truncated server reply: " + line);
211
212 try
213 {
214 _replyCode = Integer.parseInt(code = line.substring(0, 3));
215 }
216 catch (NumberFormatException e)
217 {
218 throw new MalformedServerReplyException(
219 "Could not parse response code.\nServer Reply: " + line);
220 }
221
222 _replyLines.addElement(line);
223
224 // Get extra lines if message continues.
225 if (length > 3 && line.charAt(3) == '-')
226 {
227 do
228 {
229 line = _reader.readLine();
230
231 if (line == null)
232 throw new SMTPConnectionClosedException(
233 "Connection closed without indication.");
234
235 _replyLines.addElement(line);
236
237 // The length() check handles problems that could arise from readLine()
238 // returning too soon after encountering a naked CR or some other
239 // anomaly.
240 }
241 while (!(line.length() >= 4 && line.charAt(3) != '-' &&
242 Character.isDigit(line.charAt(0))));
243 // This is too strong a condition because a non-conforming server
244 // could screw things up like ftp.funet.fi does for FTP
245 // line.startsWith(code)));
246 }
247
248 if (_commandSupport_.getListenerCount() > 0)
249 _commandSupport_.fireReplyReceived(_replyCode, getReplyString());
250
251 if (_replyCode == SMTPReply.SERVICE_NOT_AVAILABLE)
252 throw new SMTPConnectionClosedException(
253 "SMTP response 421 received. Server closed connection.");
254 }
255
256 /**** Initiates control connections and gets initial reply. ***/
257 protected void _connectAction_() throws IOException
258 {
259 super._connectAction_();
260 _reader =
261 new BufferedReader(new InputStreamReader(_input_));
262 _writer =
263 new BufferedWriter(new OutputStreamWriter(_output_));
264 __getReply();
265 }
266
267
268 /****
269 * Adds a ProtocolCommandListener. Delegates this task to
270 * <a href="#_commandSupport_"> _commandSupport_ </a>.
271 * <p>
272 * @param listener The ProtocolCommandListener to add.
273 ***/
274 public void addProtocolCommandListener(ProtocolCommandListener listener)
275 {
276 _commandSupport_.addProtocolCommandListener(listener);
277 }
278
279 /****
280 * Removes a ProtocolCommandListener. Delegates this task to
281 * <a href="#_commandSupport_"> _commandSupport_ </a>.
282 * <p>
283 * @param listener The ProtocolCommandListener to remove.
284 ***/
285 public void removeProtocolCommandistener(ProtocolCommandListener listener)
286 {
287 _commandSupport_.removeProtocolCommandListener(listener);
288 }
289
290
291 /****
292 * Closes the connection to the SMTP server and sets to null
293 * some internal data so that the memory may be reclaimed by the
294 * garbage collector. The reply text and code information from the
295 * last command is voided so that the memory it used may be reclaimed.
296 * <p>
297 * @exception IOException If an error occurs while disconnecting.
298 ***/
299 public void disconnect() throws IOException
300 {
301 super.disconnect();
302 _reader = null;
303 _writer = null;
304 _replyString = null;
305 _replyLines.setSize(0);
306 _newReplyString = false;
307 }
308
309
310 /****
311 * Sends an SMTP command to the server, waits for a reply and returns the
312 * numerical response code. After invocation, for more detailed
313 * information, the actual reply text can be accessed by calling
314 * <a href="#getReplyString"> getReplyString </a> or
315 * <a href="#getReplyStrings"> getReplyStrings </a>.
316 * <p>
317 * @param command The text representation of the SMTP command to send.
318 * @param args The arguments to the SMTP command. If this parameter is
319 * set to null, then the command is sent with no argument.
320 * @return The integer value of the SMTP reply code returned by the server
321 * in response to the command.
322 * @exception SMTPConnectionClosedException
323 * If the SMTP server prematurely closes the connection as a result
324 * of the client being idle or some other reason causing the server
325 * to send SMTP reply code 421. This exception may be caught either
326 * as an IOException or independently as itself.
327 * @exception IOException If an I/O error occurs while either sending the
328 * command or receiving the server reply.
329 ***/
330 public int sendCommand(String command, String args) throws IOException
331 {
332 return __sendCommand(command, args, true);
333 }
334
335
336 /****
337 * Sends an SMTP command to the server, waits for a reply and returns the
338 * numerical response code. After invocation, for more detailed
339 * information, the actual reply text can be accessed by calling
340 * <a href="#getReplyString"> getReplyString </a> or
341 * <a href="#getReplyStrings"> getReplyStrings </a>.
342 * <p>
343 * @param command The SMTPCommand constant corresponding to the SMTP command
344 * to send.
345 * @param args The arguments to the SMTP command. If this parameter is
346 * set to null, then the command is sent with no argument.
347 * @return The integer value of the SMTP reply code returned by the server
348 * in response to the command.
349 * @exception SMTPConnectionClosedException
350 * If the SMTP server prematurely closes the connection as a result
351 * of the client being idle or some other reason causing the server
352 * to send SMTP reply code 421. This exception may be caught either
353 * as an IOException or independently as itself.
354 * @exception IOException If an I/O error occurs while either sending the
355 * command or receiving the server reply.
356 ***/
357 public int sendCommand(int command, String args) throws IOException
358 {
359 return sendCommand(SMTPCommand._commands[command], args);
360 }
361
362
363 /****
364 * Sends an SMTP command with no arguments to the server, waits for a
365 * reply and returns the numerical response code. After invocation, for
366 * more detailed information, the actual reply text can be accessed by
367 * calling <a href="#getReplyString"> getReplyString </a> or
368 * <a href="#getReplyStrings"> getReplyStrings </a>.
369 * <p>
370 * @param command The text representation of the SMTP command to send.
371 * @return The integer value of the SMTP reply code returned by the server
372 * in response to the command.
373 * @exception SMTPConnectionClosedException
374 * If the SMTP server prematurely closes the connection as a result
375 * of the client being idle or some other reason causing the server
376 * to send SMTP reply code 421. This exception may be caught either
377 * as an IOException or independently as itself.
378 * @exception IOException If an I/O error occurs while either sending the
379 * command or receiving the server reply.
380 ***/
381 public int sendCommand(String command) throws IOException
382 {
383 return sendCommand(command, null);
384 }
385
386
387 /****
388 * Sends an SMTP command with no arguments to the server, waits for a
389 * reply and returns the numerical response code. After invocation, for
390 * more detailed information, the actual reply text can be accessed by
391 * calling <a href="#getReplyString"> getReplyString </a> or
392 * <a href="#getReplyStrings"> getReplyStrings </a>.
393 * <p>
394 * @param command The SMTPCommand constant corresponding to the SMTP command
395 * to send.
396 * @return The integer value of the SMTP reply code returned by the server
397 * in response to the command.
398 * @exception SMTPConnectionClosedException
399 * If the SMTP server prematurely closes the connection as a result
400 * of the client being idle or some other reason causing the server
401 * to send SMTP reply code 421. This exception may be caught either
402 * as an IOException or independently as itself.
403 * @exception IOException If an I/O error occurs while either sending the
404 * command or receiving the server reply.
405 ***/
406 public int sendCommand(int command) throws IOException
407 {
408 return sendCommand(command, null);
409 }
410
411
412 /****
413 * Returns the integer value of the reply code of the last SMTP reply.
414 * You will usually only use this method after you connect to the
415 * SMTP server to check that the connection was successful since
416 * <code> connect </code> is of type void.
417 * <p>
418 * @return The integer value of the reply code of the last SMTP reply.
419 ***/
420 public int getReplyCode()
421 {
422 return _replyCode;
423 }
424
425 /****
426 * Fetches a reply from the SMTP server and returns the integer reply
427 * code. After calling this method, the actual reply text can be accessed
428 * from either calling <a href="#getReplyString"> getReplyString </a> or
429 * <a href="#getReplyStrings"> getReplyStrings </a>. Only use this
430 * method if you are implementing your own SMTP client or if you need to
431 * fetch a secondary response from the SMTP server.
432 * <p>
433 * @return The integer value of the reply code of the fetched SMTP reply.
434 * @exception SMTPConnectionClosedException
435 * If the SMTP server prematurely closes the connection as a result
436 * of the client being idle or some other reason causing the server
437 * to send SMTP reply code 421. This exception may be caught either
438 * as an IOException or independently as itself.
439 * @exception IOException If an I/O error occurs while receiving the
440 * server reply.
441 ***/
442 public int getReply() throws IOException
443 {
444 __getReply();
445 return _replyCode;
446 }
447
448
449 /****
450 * Returns the lines of text from the last SMTP server response as an array
451 * of strings, one entry per line. The end of line markers of each are
452 * stripped from each line.
453 * <p>
454 * @return The lines of text from the last SMTP response as an array.
455 ***/
456 public String[] getReplyStrings()
457 {
458 String[] lines;
459 lines = new String[_replyLines.size()];
460 _replyLines.copyInto(lines);
461 return lines;
462 }
463
464 /****
465 * Returns the entire text of the last SMTP server response exactly
466 * as it was received, including all end of line markers in NETASCII
467 * format.
468 * <p>
469 * @return The entire text from the last SMTP response as a String.
470 ***/
471 public String getReplyString()
472 {
473 Enumeration enum;
474 StringBuffer buffer;
475
476 if (!_newReplyString)
477 return _replyString;
478
479 buffer = new StringBuffer(256);
480 enum = _replyLines.elements();
481 while (enum.hasMoreElements())
482 {
483 buffer.append((String)enum.nextElement());
484 buffer.append(SocketClient.NETASCII_EOL);
485 }
486
487 _newReplyString = false;
488
489 return (_replyString = buffer.toString());
490 }
491
492
493 /****
494 * A convenience method to send the SMTP HELO command to the server,
495 * receive the reply, and return the reply code.
496 * <p>
497 * @param hostname The hostname of the sender.
498 * @return The reply code received from the server.
499 * @exception SMTPConnectionClosedException
500 * If the SMTP server prematurely closes the connection as a result
501 * of the client being idle or some other reason causing the server
502 * to send SMTP reply code 421. This exception may be caught either
503 * as an IOException or independently as itself.
504 * @exception IOException If an I/O error occurs while either sending the
505 * command or receiving the server reply.
506 ***/
507 public int helo(String hostname) throws IOException
508 {
509 return sendCommand(SMTPCommand.HELO, hostname);
510 }
511
512
513 /****
514 * A convenience method to send the SMTP MAIL command to the server,
515 * receive the reply, and return the reply code.
516 * <p>
517 * @param reversePath The reverese path.
518 * @return The reply code received from the server.
519 * @exception SMTPConnectionClosedException
520 * If the SMTP server prematurely closes the connection as a result
521 * of the client being idle or some other reason causing the server
522 * to send SMTP reply code 421. This exception may be caught either
523 * as an IOException or independently as itself.
524 * @exception IOException If an I/O error occurs while either sending the
525 * command or receiving the server reply.
526 ***/
527 public int mail(String reversePath) throws IOException
528 {
529 return __sendCommand(SMTPCommand.MAIL, reversePath, false);
530 }
531
532
533 /****
534 * A convenience method to send the SMTP RCPT command to the server,
535 * receive the reply, and return the reply code.
536 * <p>
537 * @param forwardPath The forward path.
538 * @return The reply code received from the server.
539 * @exception SMTPConnectionClosedException
540 * If the SMTP server prematurely closes the connection as a result
541 * of the client being idle or some other reason causing the server
542 * to send SMTP reply code 421. This exception may be caught either
543 * as an IOException or independently as itself.
544 * @exception IOException If an I/O error occurs while either sending the
545 * command or receiving the server reply.
546 ***/
547 public int rcpt(String forwardPath) throws IOException
548 {
549 return __sendCommand(SMTPCommand.RCPT, forwardPath, false);
550 }
551
552
553 /****
554 * A convenience method to send the SMTP DATA command to the server,
555 * receive the reply, and return the reply code.
556 * <p>
557 * @return The reply code received from the server.
558 * @exception SMTPConnectionClosedException
559 * If the SMTP server prematurely closes the connection as a result
560 * of the client being idle or some other reason causing the server
561 * to send SMTP reply code 421. This exception may be caught either
562 * as an IOException or independently as itself.
563 * @exception IOException If an I/O error occurs while either sending the
564 * command or receiving the server reply.
565 ***/
566 public int data() throws IOException
567 {
568 return sendCommand(SMTPCommand.DATA);
569 }
570
571
572 /****
573 * A convenience method to send the SMTP SEND command to the server,
574 * receive the reply, and return the reply code.
575 * <p>
576 * @param reversePath The reverese path.
577 * @return The reply code received from the server.
578 * @exception SMTPConnectionClosedException
579 * If the SMTP server prematurely closes the connection as a result
580 * of the client being idle or some other reason causing the server
581 * to send SMTP reply code 421. This exception may be caught either
582 * as an IOException or independently as itself.
583 * @exception IOException If an I/O error occurs while either sending the
584 * command or receiving the server reply.
585 ***/
586 public int send(String reversePath) throws IOException
587 {
588 return sendCommand(SMTPCommand.SEND, reversePath);
589 }
590
591
592 /****
593 * A convenience method to send the SMTP SOML command to the server,
594 * receive the reply, and return the reply code.
595 * <p>
596 * @param reversePath The reverese path.
597 * @return The reply code received from the server.
598 * @exception SMTPConnectionClosedException
599 * If the SMTP server prematurely closes the connection as a result
600 * of the client being idle or some other reason causing the server
601 * to send SMTP reply code 421. This exception may be caught either
602 * as an IOException or independently as itself.
603 * @exception IOException If an I/O error occurs while either sending the
604 * command or receiving the server reply.
605 ***/
606 public int soml(String reversePath) throws IOException
607 {
608 return sendCommand(SMTPCommand.SOML, reversePath);
609 }
610
611
612 /****
613 * A convenience method to send the SMTP SAML command to the server,
614 * receive the reply, and return the reply code.
615 * <p>
616 * @param reversePath The reverese path.
617 * @return The reply code received from the server.
618 * @exception SMTPConnectionClosedException
619 * If the SMTP server prematurely closes the connection as a result
620 * of the client being idle or some other reason causing the server
621 * to send SMTP reply code 421. This exception may be caught either
622 * as an IOException or independently as itself.
623 * @exception IOException If an I/O error occurs while either sending the
624 * command or receiving the server reply.
625 ***/
626 public int saml(String reversePath) throws IOException
627 {
628 return sendCommand(SMTPCommand.SAML, reversePath);
629 }
630
631
632 /****
633 * A convenience method to send the SMTP RSET command to the server,
634 * receive the reply, and return the reply code.
635 * <p>
636 * @return The reply code received from the server.
637 * @exception SMTPConnectionClosedException
638 * If the SMTP server prematurely closes the connection as a result
639 * of the client being idle or some other reason causing the server
640 * to send SMTP reply code 421. This exception may be caught either
641 * as an IOException or independently as itself.
642 * @exception IOException If an I/O error occurs while either sending the
643 * command or receiving the server reply.
644 ***/
645 public int rset() throws IOException
646 {
647 return sendCommand(SMTPCommand.RSET);
648 }
649
650
651 /****
652 * A convenience method to send the SMTP VRFY command to the server,
653 * receive the reply, and return the reply code.
654 * <p>
655 * @param user The user address to verify.
656 * @return The reply code received from the server.
657 * @exception SMTPConnectionClosedException
658 * If the SMTP server prematurely closes the connection as a result
659 * of the client being idle or some other reason causing the server
660 * to send SMTP reply code 421. This exception may be caught either
661 * as an IOException or independently as itself.
662 * @exception IOException If an I/O error occurs while either sending the
663 * command or receiving the server reply.
664 ***/
665 public int vrfy(String user) throws IOException
666 {
667 return sendCommand(SMTPCommand.VRFY, user);
668 }
669
670
671 /****
672 * A convenience method to send the SMTP VRFY command to the server,
673 * receive the reply, and return the reply code.
674 * <p>
675 * @param name The name to expand.
676 * @return The reply code received from the server.
677 * @exception SMTPConnectionClosedException
678 * If the SMTP server prematurely closes the connection as a result
679 * of the client being idle or some other reason causing the server
680 * to send SMTP reply code 421. This exception may be caught either
681 * as an IOException or independently as itself.
682 * @exception IOException If an I/O error occurs while either sending the
683 * command or receiving the server reply.
684 ***/
685 public int expn(String name) throws IOException
686 {
687 return sendCommand(SMTPCommand.EXPN, name);
688 }
689
690 /****
691 * A convenience method to send the SMTP HELP command to the server,
692 * receive the reply, and return the reply code.
693 * <p>
694 * @return The reply code received from the server.
695 * @exception SMTPConnectionClosedException
696 * If the SMTP server prematurely closes the connection as a result
697 * of the client being idle or some other reason causing the server
698 * to send SMTP reply code 421. This exception may be caught either
699 * as an IOException or independently as itself.
700 * @exception IOException If an I/O error occurs while either sending the
701 * command or receiving the server reply.
702 ***/
703 public int help() throws IOException
704 {
705 return sendCommand(SMTPCommand.HELP);
706 }
707
708 /****
709 * A convenience method to send the SMTP HELP command to the server,
710 * receive the reply, and return the reply code.
711 * <p>
712 * @param command The command name on which to request help.
713 * @return The reply code received from the server.
714 * @exception SMTPConnectionClosedException
715 * If the SMTP server prematurely closes the connection as a result
716 * of the client being idle or some other reason causing the server
717 * to send SMTP reply code 421. This exception may be caught either
718 * as an IOException or independently as itself.
719 * @exception IOException If an I/O error occurs while either sending the
720 * command or receiving the server reply.
721 ***/
722 public int help(String command) throws IOException
723 {
724 return sendCommand(SMTPCommand.HELP, command);
725 }
726
727 /****
728 * A convenience method to send the SMTP NOOP command to the server,
729 * receive the reply, and return the reply code.
730 * <p>
731 * @return The reply code received from the server.
732 * @exception SMTPConnectionClosedException
733 * If the SMTP server prematurely closes the connection as a result
734 * of the client being idle or some other reason causing the server
735 * to send SMTP reply code 421. This exception may be caught either
736 * as an IOException or independently as itself.
737 * @exception IOException If an I/O error occurs while either sending the
738 * command or receiving the server reply.
739 ***/
740 public int noop() throws IOException
741 {
742 return sendCommand(SMTPCommand.NOOP);
743 }
744
745
746 /****
747 * A convenience method to send the SMTP TURN command to the server,
748 * receive the reply, and return the reply code.
749 * <p>
750 * @return The reply code received from the server.
751 * @exception SMTPConnectionClosedException
752 * If the SMTP server prematurely closes the connection as a result
753 * of the client being idle or some other reason causing the server
754 * to send SMTP reply code 421. This exception may be caught either
755 * as an IOException or independently as itself.
756 * @exception IOException If an I/O error occurs while either sending the
757 * command or receiving the server reply.
758 ***/
759 public int turn() throws IOException
760 {
761 return sendCommand(SMTPCommand.TURN);
762 }
763
764
765 /****
766 * A convenience method to send the SMTP QUIT command to the server,
767 * receive the reply, and return the reply code.
768 * <p>
769 * @return The reply code received from the server.
770 * @exception SMTPConnectionClosedException
771 * If the SMTP server prematurely closes the connection as a result
772 * of the client being idle or some other reason causing the server
773 * to send SMTP reply code 421. This exception may be caught either
774 * as an IOException or independently as itself.
775 * @exception IOException If an I/O error occurs while either sending the
776 * command or receiving the server reply.
777 ***/
778 public int quit() throws IOException
779 {
780 return sendCommand(SMTPCommand.QUIT);
781 }
782
783 }
This page was automatically generated by Maven