1. /*
  2. * Copyright 2001-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. package org.apache.commons.net.smtp;
  17. import java.io.BufferedReader;
  18. import java.io.BufferedWriter;
  19. import java.io.IOException;
  20. import java.io.InputStreamReader;
  21. import java.io.OutputStreamWriter;
  22. import java.util.Enumeration;
  23. import java.util.Vector;
  24. import org.apache.commons.net.MalformedServerReplyException;
  25. import org.apache.commons.net.ProtocolCommandListener;
  26. import org.apache.commons.net.ProtocolCommandSupport;
  27. import org.apache.commons.net.SocketClient;
  28. /***
  29. * SMTP provides the basic the functionality necessary to implement your
  30. * own SMTP client. To derive the full benefits of the SMTP class requires
  31. * some knowledge of the FTP protocol defined in RFC 821. However, there
  32. * is no reason why you should have to use the SMTP class. The
  33. * <a href="org.apache.commons.net.smtp.SMTPClient.html"> SMTPClient </a> class,
  34. * derived from SMTP,
  35. * implements all the functionality required of an SMTP client. The
  36. * SMTP class is made public to provide access to various SMTP constants
  37. * and to make it easier for adventurous programmers (or those with
  38. * special needs) to interact with the SMTP protocol and implement their
  39. * own clients. A set of methods with names corresponding to the SMTP
  40. * command names are provided to facilitate this interaction.
  41. * <p>
  42. * You should keep in mind that the SMTP server may choose to prematurely
  43. * close a connection for various reasons. The SMTP class will detect a
  44. * premature SMTP server connection closing when it receives a
  45. * <a href="org.apache.commons.net.smtp.SMTPReply.html#SERVICE_NOT_AVAILABLE">
  46. * SMTPReply.SERVICE_NOT_AVAILABLE </a> response to a command.
  47. * When that occurs, the SMTP class method encountering that reply will throw
  48. * an <a href="org.apache.commons.net.smtp.SMTPConnectionClosedException.html">
  49. * SMTPConnectionClosedException </a>.
  50. * <code>SMTPConectionClosedException</code>
  51. * is a subclass of <code> IOException </code> and therefore need not be
  52. * caught separately, but if you are going to catch it separately, its
  53. * catch block must appear before the more general <code> IOException </code>
  54. * catch block. When you encounter an
  55. * <a href="org.apache.commons.net.smtp.SMTPConnectionClosedException.html">
  56. * SMTPConnectionClosedException </a>, you must disconnect the connection with
  57. * <a href="org.apache.commons.net.SocketClient.html#disconnect"> disconnect() </a>
  58. * to properly clean up the system resources used by SMTP. Before
  59. * disconnecting, you may check the
  60. * last reply code and text with
  61. * <a href="#getReplyCode"> getReplyCode </a>,
  62. * <a href="#getReplyString"> getReplyString </a>,
  63. * and <a href="#getReplyStrings"> getReplyStrings</a>.
  64. * <p>
  65. * Rather than list it separately for each method, we mention here that
  66. * every method communicating with the server and throwing an IOException
  67. * can also throw a
  68. * <a href="org.apache.commons.net.MalformedServerReplyException.html">
  69. * MalformedServerReplyException </a>, which is a subclass
  70. * of IOException. A MalformedServerReplyException will be thrown when
  71. * the reply received from the server deviates enough from the protocol
  72. * specification that it cannot be interpreted in a useful manner despite
  73. * attempts to be as lenient as possible.
  74. * <p>
  75. * <p>
  76. * @author Daniel F. Savarese
  77. * @see SMTPClient
  78. * @see SMTPConnectionClosedException
  79. * @see org.apache.commons.net.MalformedServerReplyException
  80. ***/
  81. public class SMTP extends SocketClient
  82. {
  83. /*** The default SMTP port (25). ***/
  84. public static final int DEFAULT_PORT = 25;
  85. // We have to ensure that the protocol communication is in ASCII
  86. // but we use ISO-8859-1 just in case 8-bit characters cross
  87. // the wire.
  88. private static final String __DEFAULT_ENCODING = "ISO-8859-1";
  89. private StringBuffer __commandBuffer;
  90. BufferedReader _reader;
  91. BufferedWriter _writer;
  92. int _replyCode;
  93. Vector _replyLines;
  94. boolean _newReplyString;
  95. String _replyString;
  96. /***
  97. * A ProtocolCommandSupport object used to manage the registering of
  98. * ProtocolCommandListeners and te firing of ProtocolCommandEvents.
  99. ***/
  100. protected ProtocolCommandSupport _commandSupport_;
  101. /***
  102. * The default SMTP constructor. Sets the default port to
  103. * <code>DEFAULT_PORT</code> and initializes internal data structures
  104. * for saving SMTP reply information.
  105. ***/
  106. public SMTP()
  107. {
  108. setDefaultPort(DEFAULT_PORT);
  109. __commandBuffer = new StringBuffer();
  110. _replyLines = new Vector();
  111. _newReplyString = false;
  112. _replyString = null;
  113. _commandSupport_ = new ProtocolCommandSupport(this);
  114. }
  115. private int __sendCommand(String command, String args, boolean includeSpace)
  116. throws IOException
  117. {
  118. String message;
  119. __commandBuffer.setLength(0);
  120. __commandBuffer.append(command);
  121. if (args != null)
  122. {
  123. if (includeSpace)
  124. __commandBuffer.append(' ');
  125. __commandBuffer.append(args);
  126. }
  127. __commandBuffer.append(SocketClient.NETASCII_EOL);
  128. _writer.write(message = __commandBuffer.toString());
  129. _writer.flush();
  130. if (_commandSupport_.getListenerCount() > 0)
  131. _commandSupport_.fireCommandSent(command, message);
  132. __getReply();
  133. return _replyCode;
  134. }
  135. private int __sendCommand(int command, String args, boolean includeSpace)
  136. throws IOException
  137. {
  138. return __sendCommand(SMTPCommand._commands[command], args, includeSpace);
  139. }
  140. private void __getReply() throws IOException
  141. {
  142. int length;
  143. _newReplyString = true;
  144. _replyLines.setSize(0);
  145. String line = _reader.readLine();
  146. if (line == null)
  147. throw new SMTPConnectionClosedException(
  148. "Connection closed without indication.");
  149. // In case we run into an anomaly we don't want fatal index exceptions
  150. // to be thrown.
  151. length = line.length();
  152. if (length < 3)
  153. throw new MalformedServerReplyException(
  154. "Truncated server reply: " + line);
  155. try
  156. {
  157. String code = line.substring(0, 3);
  158. _replyCode = Integer.parseInt(code);
  159. }
  160. catch (NumberFormatException e)
  161. {
  162. throw new MalformedServerReplyException(
  163. "Could not parse response code.\nServer Reply: " + line);
  164. }
  165. _replyLines.addElement(line);
  166. // Get extra lines if message continues.
  167. if (length > 3 && line.charAt(3) == '-')
  168. {
  169. do
  170. {
  171. line = _reader.readLine();
  172. if (line == null)
  173. throw new SMTPConnectionClosedException(
  174. "Connection closed without indication.");
  175. _replyLines.addElement(line);
  176. // The length() check handles problems that could arise from readLine()
  177. // returning too soon after encountering a naked CR or some other
  178. // anomaly.
  179. }
  180. while (!(line.length() >= 4 && line.charAt(3) != '-' &&
  181. Character.isDigit(line.charAt(0))));
  182. // This is too strong a condition because a non-conforming server
  183. // could screw things up like ftp.funet.fi does for FTP
  184. // line.startsWith(code)));
  185. }
  186. if (_commandSupport_.getListenerCount() > 0)
  187. _commandSupport_.fireReplyReceived(_replyCode, getReplyString());
  188. if (_replyCode == SMTPReply.SERVICE_NOT_AVAILABLE)
  189. throw new SMTPConnectionClosedException(
  190. "SMTP response 421 received. Server closed connection.");
  191. }
  192. /*** Initiates control connections and gets initial reply. ***/
  193. protected void _connectAction_() throws IOException
  194. {
  195. super._connectAction_();
  196. _reader =
  197. new BufferedReader(new InputStreamReader(_input_,
  198. __DEFAULT_ENCODING));
  199. _writer =
  200. new BufferedWriter(new OutputStreamWriter(_output_,
  201. __DEFAULT_ENCODING));
  202. __getReply();
  203. }
  204. /***
  205. * Adds a ProtocolCommandListener. Delegates this task to
  206. * <a href="#_commandSupport_"> _commandSupport_ </a>.
  207. * <p>
  208. * @param listener The ProtocolCommandListener to add.
  209. ***/
  210. public void addProtocolCommandListener(ProtocolCommandListener listener)
  211. {
  212. _commandSupport_.addProtocolCommandListener(listener);
  213. }
  214. /***
  215. * Removes a ProtocolCommandListener. Delegates this task to
  216. * <a href="#_commandSupport_"> _commandSupport_ </a>.
  217. * <p>
  218. * @param listener The ProtocolCommandListener to remove.
  219. ***/
  220. public void removeProtocolCommandistener(ProtocolCommandListener listener)
  221. {
  222. _commandSupport_.removeProtocolCommandListener(listener);
  223. }
  224. /***
  225. * Closes the connection to the SMTP server and sets to null
  226. * some internal data so that the memory may be reclaimed by the
  227. * garbage collector. The reply text and code information from the
  228. * last command is voided so that the memory it used may be reclaimed.
  229. * <p>
  230. * @exception IOException If an error occurs while disconnecting.
  231. ***/
  232. public void disconnect() throws IOException
  233. {
  234. super.disconnect();
  235. _reader = null;
  236. _writer = null;
  237. _replyString = null;
  238. _replyLines.setSize(0);
  239. _newReplyString = false;
  240. }
  241. /***
  242. * Sends an SMTP command to the server, waits for a reply and returns the
  243. * numerical response code. After invocation, for more detailed
  244. * information, the actual reply text can be accessed by calling
  245. * <a href="#getReplyString"> getReplyString </a> or
  246. * <a href="#getReplyStrings"> getReplyStrings </a>.
  247. * <p>
  248. * @param command The text representation of the SMTP command to send.
  249. * @param args The arguments to the SMTP command. If this parameter is
  250. * set to null, then the command is sent with no argument.
  251. * @return The integer value of the SMTP reply code returned by the server
  252. * in response to the command.
  253. * @exception SMTPConnectionClosedException
  254. * If the SMTP server prematurely closes the connection as a result
  255. * of the client being idle or some other reason causing the server
  256. * to send SMTP reply code 421. This exception may be caught either
  257. * as an IOException or independently as itself.
  258. * @exception IOException If an I/O error occurs while either sending the
  259. * command or receiving the server reply.
  260. ***/
  261. public int sendCommand(String command, String args) throws IOException
  262. {
  263. return __sendCommand(command, args, true);
  264. }
  265. /***
  266. * Sends an SMTP command to the server, waits for a reply and returns the
  267. * numerical response code. After invocation, for more detailed
  268. * information, the actual reply text can be accessed by calling
  269. * <a href="#getReplyString"> getReplyString </a> or
  270. * <a href="#getReplyStrings"> getReplyStrings </a>.
  271. * <p>
  272. * @param command The SMTPCommand constant corresponding to the SMTP command
  273. * to send.
  274. * @param args The arguments to the SMTP command. If this parameter is
  275. * set to null, then the command is sent with no argument.
  276. * @return The integer value of the SMTP reply code returned by the server
  277. * in response to the command.
  278. * @exception SMTPConnectionClosedException
  279. * If the SMTP server prematurely closes the connection as a result
  280. * of the client being idle or some other reason causing the server
  281. * to send SMTP reply code 421. This exception may be caught either
  282. * as an IOException or independently as itself.
  283. * @exception IOException If an I/O error occurs while either sending the
  284. * command or receiving the server reply.
  285. ***/
  286. public int sendCommand(int command, String args) throws IOException
  287. {
  288. return sendCommand(SMTPCommand._commands[command], args);
  289. }
  290. /***
  291. * Sends an SMTP command with no arguments to the server, waits for a
  292. * reply and returns the numerical response code. After invocation, for
  293. * more detailed information, the actual reply text can be accessed by
  294. * calling <a href="#getReplyString"> getReplyString </a> or
  295. * <a href="#getReplyStrings"> getReplyStrings </a>.
  296. * <p>
  297. * @param command The text representation of the SMTP command to send.
  298. * @return The integer value of the SMTP reply code returned by the server
  299. * in response to the command.
  300. * @exception SMTPConnectionClosedException
  301. * If the SMTP server prematurely closes the connection as a result
  302. * of the client being idle or some other reason causing the server
  303. * to send SMTP reply code 421. This exception may be caught either
  304. * as an IOException or independently as itself.
  305. * @exception IOException If an I/O error occurs while either sending the
  306. * command or receiving the server reply.
  307. ***/
  308. public int sendCommand(String command) throws IOException
  309. {
  310. return sendCommand(command, null);
  311. }
  312. /***
  313. * Sends an SMTP command with no arguments to the server, waits for a
  314. * reply and returns the numerical response code. After invocation, for
  315. * more detailed information, the actual reply text can be accessed by
  316. * calling <a href="#getReplyString"> getReplyString </a> or
  317. * <a href="#getReplyStrings"> getReplyStrings </a>.
  318. * <p>
  319. * @param command The SMTPCommand constant corresponding to the SMTP command
  320. * to send.
  321. * @return The integer value of the SMTP reply code returned by the server
  322. * in response to the command.
  323. * @exception SMTPConnectionClosedException
  324. * If the SMTP server prematurely closes the connection as a result
  325. * of the client being idle or some other reason causing the server
  326. * to send SMTP reply code 421. This exception may be caught either
  327. * as an IOException or independently as itself.
  328. * @exception IOException If an I/O error occurs while either sending the
  329. * command or receiving the server reply.
  330. ***/
  331. public int sendCommand(int command) throws IOException
  332. {
  333. return sendCommand(command, null);
  334. }
  335. /***
  336. * Returns the integer value of the reply code of the last SMTP reply.
  337. * You will usually only use this method after you connect to the
  338. * SMTP server to check that the connection was successful since
  339. * <code> connect </code> is of type void.
  340. * <p>
  341. * @return The integer value of the reply code of the last SMTP reply.
  342. ***/
  343. public int getReplyCode()
  344. {
  345. return _replyCode;
  346. }
  347. /***
  348. * Fetches a reply from the SMTP server and returns the integer reply
  349. * code. After calling this method, the actual reply text can be accessed
  350. * from either calling <a href="#getReplyString"> getReplyString </a> or
  351. * <a href="#getReplyStrings"> getReplyStrings </a>. Only use this
  352. * method if you are implementing your own SMTP client or if you need to
  353. * fetch a secondary response from the SMTP server.
  354. * <p>
  355. * @return The integer value of the reply code of the fetched SMTP reply.
  356. * @exception SMTPConnectionClosedException
  357. * If the SMTP server prematurely closes the connection as a result
  358. * of the client being idle or some other reason causing the server
  359. * to send SMTP reply code 421. This exception may be caught either
  360. * as an IOException or independently as itself.
  361. * @exception IOException If an I/O error occurs while receiving the
  362. * server reply.
  363. ***/
  364. public int getReply() throws IOException
  365. {
  366. __getReply();
  367. return _replyCode;
  368. }
  369. /***
  370. * Returns the lines of text from the last SMTP server response as an array
  371. * of strings, one entry per line. The end of line markers of each are
  372. * stripped from each line.
  373. * <p>
  374. * @return The lines of text from the last SMTP response as an array.
  375. ***/
  376. public String[] getReplyStrings()
  377. {
  378. String[] lines;
  379. lines = new String[_replyLines.size()];
  380. _replyLines.copyInto(lines);
  381. return lines;
  382. }
  383. /***
  384. * Returns the entire text of the last SMTP server response exactly
  385. * as it was received, including all end of line markers in NETASCII
  386. * format.
  387. * <p>
  388. * @return The entire text from the last SMTP response as a String.
  389. ***/
  390. public String getReplyString()
  391. {
  392. Enumeration enum;
  393. StringBuffer buffer;
  394. if (!_newReplyString)
  395. return _replyString;
  396. buffer = new StringBuffer(256);
  397. enum = _replyLines.elements();
  398. while (enum.hasMoreElements())
  399. {
  400. buffer.append((String)enum.nextElement());
  401. buffer.append(SocketClient.NETASCII_EOL);
  402. }
  403. _newReplyString = false;
  404. return (_replyString = buffer.toString());
  405. }
  406. /***
  407. * A convenience method to send the SMTP HELO command to the server,
  408. * receive the reply, and return the reply code.
  409. * <p>
  410. * @param hostname The hostname of the sender.
  411. * @return The reply code received from the server.
  412. * @exception SMTPConnectionClosedException
  413. * If the SMTP server prematurely closes the connection as a result
  414. * of the client being idle or some other reason causing the server
  415. * to send SMTP reply code 421. This exception may be caught either
  416. * as an IOException or independently as itself.
  417. * @exception IOException If an I/O error occurs while either sending the
  418. * command or receiving the server reply.
  419. ***/
  420. public int helo(String hostname) throws IOException
  421. {
  422. return sendCommand(SMTPCommand.HELO, hostname);
  423. }
  424. /***
  425. * A convenience method to send the SMTP MAIL command to the server,
  426. * receive the reply, and return the reply code.
  427. * <p>
  428. * @param reversePath The reverese path.
  429. * @return The reply code received from the server.
  430. * @exception SMTPConnectionClosedException
  431. * If the SMTP server prematurely closes the connection as a result
  432. * of the client being idle or some other reason causing the server
  433. * to send SMTP reply code 421. This exception may be caught either
  434. * as an IOException or independently as itself.
  435. * @exception IOException If an I/O error occurs while either sending the
  436. * command or receiving the server reply.
  437. ***/
  438. public int mail(String reversePath) throws IOException
  439. {
  440. return __sendCommand(SMTPCommand.MAIL, reversePath, false);
  441. }
  442. /***
  443. * A convenience method to send the SMTP RCPT command to the server,
  444. * receive the reply, and return the reply code.
  445. * <p>
  446. * @param forwardPath The forward path.
  447. * @return The reply code received from the server.
  448. * @exception SMTPConnectionClosedException
  449. * If the SMTP server prematurely closes the connection as a result
  450. * of the client being idle or some other reason causing the server
  451. * to send SMTP reply code 421. This exception may be caught either
  452. * as an IOException or independently as itself.
  453. * @exception IOException If an I/O error occurs while either sending the
  454. * command or receiving the server reply.
  455. ***/
  456. public int rcpt(String forwardPath) throws IOException
  457. {
  458. return __sendCommand(SMTPCommand.RCPT, forwardPath, false);
  459. }
  460. /***
  461. * A convenience method to send the SMTP DATA command to the server,
  462. * receive the reply, and return the reply code.
  463. * <p>
  464. * @return The reply code received from the server.
  465. * @exception SMTPConnectionClosedException
  466. * If the SMTP server prematurely closes the connection as a result
  467. * of the client being idle or some other reason causing the server
  468. * to send SMTP reply code 421. This exception may be caught either
  469. * as an IOException or independently as itself.
  470. * @exception IOException If an I/O error occurs while either sending the
  471. * command or receiving the server reply.
  472. ***/
  473. public int data() throws IOException
  474. {
  475. return sendCommand(SMTPCommand.DATA);
  476. }
  477. /***
  478. * A convenience method to send the SMTP SEND command to the server,
  479. * receive the reply, and return the reply code.
  480. * <p>
  481. * @param reversePath The reverese path.
  482. * @return The reply code received from the server.
  483. * @exception SMTPConnectionClosedException
  484. * If the SMTP server prematurely closes the connection as a result
  485. * of the client being idle or some other reason causing the server
  486. * to send SMTP reply code 421. This exception may be caught either
  487. * as an IOException or independently as itself.
  488. * @exception IOException If an I/O error occurs while either sending the
  489. * command or receiving the server reply.
  490. ***/
  491. public int send(String reversePath) throws IOException
  492. {
  493. return sendCommand(SMTPCommand.SEND, reversePath);
  494. }
  495. /***
  496. * A convenience method to send the SMTP SOML command to the server,
  497. * receive the reply, and return the reply code.
  498. * <p>
  499. * @param reversePath The reverese path.
  500. * @return The reply code received from the server.
  501. * @exception SMTPConnectionClosedException
  502. * If the SMTP server prematurely closes the connection as a result
  503. * of the client being idle or some other reason causing the server
  504. * to send SMTP reply code 421. This exception may be caught either
  505. * as an IOException or independently as itself.
  506. * @exception IOException If an I/O error occurs while either sending the
  507. * command or receiving the server reply.
  508. ***/
  509. public int soml(String reversePath) throws IOException
  510. {
  511. return sendCommand(SMTPCommand.SOML, reversePath);
  512. }
  513. /***
  514. * A convenience method to send the SMTP SAML 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 saml(String reversePath) throws IOException
  528. {
  529. return sendCommand(SMTPCommand.SAML, reversePath);
  530. }
  531. /***
  532. * A convenience method to send the SMTP RSET command to the server,
  533. * receive the reply, and return the reply code.
  534. * <p>
  535. * @return The reply code received from the server.
  536. * @exception SMTPConnectionClosedException
  537. * If the SMTP server prematurely closes the connection as a result
  538. * of the client being idle or some other reason causing the server
  539. * to send SMTP reply code 421. This exception may be caught either
  540. * as an IOException or independently as itself.
  541. * @exception IOException If an I/O error occurs while either sending the
  542. * command or receiving the server reply.
  543. ***/
  544. public int rset() throws IOException
  545. {
  546. return sendCommand(SMTPCommand.RSET);
  547. }
  548. /***
  549. * A convenience method to send the SMTP VRFY command to the server,
  550. * receive the reply, and return the reply code.
  551. * <p>
  552. * @param user The user address to verify.
  553. * @return The reply code received from the server.
  554. * @exception SMTPConnectionClosedException
  555. * If the SMTP server prematurely closes the connection as a result
  556. * of the client being idle or some other reason causing the server
  557. * to send SMTP reply code 421. This exception may be caught either
  558. * as an IOException or independently as itself.
  559. * @exception IOException If an I/O error occurs while either sending the
  560. * command or receiving the server reply.
  561. ***/
  562. public int vrfy(String user) throws IOException
  563. {
  564. return sendCommand(SMTPCommand.VRFY, user);
  565. }
  566. /***
  567. * A convenience method to send the SMTP VRFY command to the server,
  568. * receive the reply, and return the reply code.
  569. * <p>
  570. * @param name The name to expand.
  571. * @return The reply code received from the server.
  572. * @exception SMTPConnectionClosedException
  573. * If the SMTP server prematurely closes the connection as a result
  574. * of the client being idle or some other reason causing the server
  575. * to send SMTP reply code 421. This exception may be caught either
  576. * as an IOException or independently as itself.
  577. * @exception IOException If an I/O error occurs while either sending the
  578. * command or receiving the server reply.
  579. ***/
  580. public int expn(String name) throws IOException
  581. {
  582. return sendCommand(SMTPCommand.EXPN, name);
  583. }
  584. /***
  585. * A convenience method to send the SMTP HELP command to the server,
  586. * receive the reply, and return the reply code.
  587. * <p>
  588. * @return The reply code received from the server.
  589. * @exception SMTPConnectionClosedException
  590. * If the SMTP server prematurely closes the connection as a result
  591. * of the client being idle or some other reason causing the server
  592. * to send SMTP reply code 421. This exception may be caught either
  593. * as an IOException or independently as itself.
  594. * @exception IOException If an I/O error occurs while either sending the
  595. * command or receiving the server reply.
  596. ***/
  597. public int help() throws IOException
  598. {
  599. return sendCommand(SMTPCommand.HELP);
  600. }
  601. /***
  602. * A convenience method to send the SMTP HELP command to the server,
  603. * receive the reply, and return the reply code.
  604. * <p>
  605. * @param command The command name on which to request help.
  606. * @return The reply code received from the server.
  607. * @exception SMTPConnectionClosedException
  608. * If the SMTP server prematurely closes the connection as a result
  609. * of the client being idle or some other reason causing the server
  610. * to send SMTP reply code 421. This exception may be caught either
  611. * as an IOException or independently as itself.
  612. * @exception IOException If an I/O error occurs while either sending the
  613. * command or receiving the server reply.
  614. ***/
  615. public int help(String command) throws IOException
  616. {
  617. return sendCommand(SMTPCommand.HELP, command);
  618. }
  619. /***
  620. * A convenience method to send the SMTP NOOP command to the server,
  621. * receive the reply, and return the reply code.
  622. * <p>
  623. * @return The reply code received from the server.
  624. * @exception SMTPConnectionClosedException
  625. * If the SMTP server prematurely closes the connection as a result
  626. * of the client being idle or some other reason causing the server
  627. * to send SMTP reply code 421. This exception may be caught either
  628. * as an IOException or independently as itself.
  629. * @exception IOException If an I/O error occurs while either sending the
  630. * command or receiving the server reply.
  631. ***/
  632. public int noop() throws IOException
  633. {
  634. return sendCommand(SMTPCommand.NOOP);
  635. }
  636. /***
  637. * A convenience method to send the SMTP TURN command to the server,
  638. * receive the reply, and return the reply code.
  639. * <p>
  640. * @return The reply code received from the server.
  641. * @exception SMTPConnectionClosedException
  642. * If the SMTP server prematurely closes the connection as a result
  643. * of the client being idle or some other reason causing the server
  644. * to send SMTP reply code 421. This exception may be caught either
  645. * as an IOException or independently as itself.
  646. * @exception IOException If an I/O error occurs while either sending the
  647. * command or receiving the server reply.
  648. ***/
  649. public int turn() throws IOException
  650. {
  651. return sendCommand(SMTPCommand.TURN);
  652. }
  653. /***
  654. * A convenience method to send the SMTP QUIT command to the server,
  655. * receive the reply, and return the reply code.
  656. * <p>
  657. * @return The reply code received from the server.
  658. * @exception SMTPConnectionClosedException
  659. * If the SMTP server prematurely closes the connection as a result
  660. * of the client being idle or some other reason causing the server
  661. * to send SMTP reply code 421. This exception may be caught either
  662. * as an IOException or independently as itself.
  663. * @exception IOException If an I/O error occurs while either sending the
  664. * command or receiving the server reply.
  665. ***/
  666. public int quit() throws IOException
  667. {
  668. return sendCommand(SMTPCommand.QUIT);
  669. }
  670. }
  671. /* Emacs configuration
  672. * Local variables: **
  673. * mode: java **
  674. * c-basic-offset: 4 **
  675. * indent-tabs-mode: nil **
  676. * End: **
  677. */