< prev index next >

src/java.base/share/classes/sun/net/smtp/SmtpClient.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.net.smtp;
  27 
  28 import java.util.StringTokenizer;
  29 import java.io.*;
  30 import java.net.*;
  31 import sun.net.TransferProtocolClient;

  32 
  33 /**
  34  * This class implements the SMTP client.
  35  * You can send a piece of mail by creating a new SmtpClient, calling
  36  * the "to" method to add destinations, calling "from" to name the
  37  * sender, calling startMessage to return a stream to which you write
  38  * the message (with RFC733 headers) and then you finally close the Smtp
  39  * Client.
  40  *
  41  * @author      James Gosling
  42  */
  43 
  44 public class SmtpClient extends TransferProtocolClient {
  45 
  46     String mailhost;
  47     SmtpPrintStream message;
  48 
  49     /**
  50      * issue the QUIT command to the SMTP server and close the connection.
  51      */


 140     }
 141 
 142     void closeMessage() throws IOException {
 143         if (message != null)
 144             message.close();
 145     }
 146 
 147     /** New SMTP client connected to host <i>host</i>. */
 148     public SmtpClient (String host) throws IOException {
 149         super();
 150         if (host != null) {
 151             try {
 152                 openServer(host);
 153                 mailhost = host;
 154                 return;
 155             } catch(Exception e) {
 156             }
 157         }
 158         try {
 159             String s;
 160             mailhost = java.security.AccessController.doPrivileged(
 161                     new sun.security.action.GetPropertyAction("mail.host"));
 162             if (mailhost != null) {
 163                 openServer(mailhost);
 164                 return;
 165             }
 166         } catch(Exception e) {
 167         }
 168         try {
 169             mailhost = "localhost";
 170             openServer(mailhost);
 171         } catch(Exception e) {
 172             mailhost = "mailhost";
 173             openServer(mailhost);
 174         }
 175     }
 176 
 177     /** Create an uninitialized SMTP client. */
 178     public SmtpClient () throws IOException {
 179         this(null);
 180     }
 181 
 182     public SmtpClient(int to) throws IOException {
 183         super();
 184         setConnectTimeout(to);
 185         try {
 186             String s;
 187             mailhost = java.security.AccessController.doPrivileged(
 188                     new sun.security.action.GetPropertyAction("mail.host"));
 189             if (mailhost != null) {
 190                 openServer(mailhost);
 191                 return;
 192             }
 193         } catch(Exception e) {
 194         }
 195         try {
 196             mailhost = "localhost";
 197             openServer(mailhost);
 198         } catch(Exception e) {
 199             mailhost = "mailhost";
 200             openServer(mailhost);
 201         }
 202     }
 203 
 204     public String getMailHost() {
 205         return mailhost;
 206     }
 207 
 208     String getEncoding () {




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.net.smtp;
  27 

  28 import java.io.*;
  29 import java.net.*;
  30 import sun.net.TransferProtocolClient;
  31 import sun.security.action.GetPropertyAction;
  32 
  33 /**
  34  * This class implements the SMTP client.
  35  * You can send a piece of mail by creating a new SmtpClient, calling
  36  * the "to" method to add destinations, calling "from" to name the
  37  * sender, calling startMessage to return a stream to which you write
  38  * the message (with RFC733 headers) and then you finally close the Smtp
  39  * Client.
  40  *
  41  * @author      James Gosling
  42  */
  43 
  44 public class SmtpClient extends TransferProtocolClient {
  45 
  46     String mailhost;
  47     SmtpPrintStream message;
  48 
  49     /**
  50      * issue the QUIT command to the SMTP server and close the connection.
  51      */


 140     }
 141 
 142     void closeMessage() throws IOException {
 143         if (message != null)
 144             message.close();
 145     }
 146 
 147     /** New SMTP client connected to host <i>host</i>. */
 148     public SmtpClient (String host) throws IOException {
 149         super();
 150         if (host != null) {
 151             try {
 152                 openServer(host);
 153                 mailhost = host;
 154                 return;
 155             } catch(Exception e) {
 156             }
 157         }
 158         try {
 159             String s;
 160             mailhost = GetPropertyAction.getProperty("mail.host");

 161             if (mailhost != null) {
 162                 openServer(mailhost);
 163                 return;
 164             }
 165         } catch(Exception e) {
 166         }
 167         try {
 168             mailhost = "localhost";
 169             openServer(mailhost);
 170         } catch(Exception e) {
 171             mailhost = "mailhost";
 172             openServer(mailhost);
 173         }
 174     }
 175 
 176     /** Create an uninitialized SMTP client. */
 177     public SmtpClient () throws IOException {
 178         this(null);
 179     }
 180 
 181     public SmtpClient(int to) throws IOException {
 182         super();
 183         setConnectTimeout(to);
 184         try {
 185             String s;
 186             mailhost = GetPropertyAction.getProperty("mail.host");

 187             if (mailhost != null) {
 188                 openServer(mailhost);
 189                 return;
 190             }
 191         } catch(Exception e) {
 192         }
 193         try {
 194             mailhost = "localhost";
 195             openServer(mailhost);
 196         } catch(Exception e) {
 197             mailhost = "mailhost";
 198             openServer(mailhost);
 199         }
 200     }
 201 
 202     public String getMailHost() {
 203         return mailhost;
 204     }
 205 
 206     String getEncoding () {


< prev index next >