View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.mail2.core;
18  
19  import java.nio.charset.StandardCharsets;
20  import java.time.Duration;
21  
22  /**
23   * Constants used by Email classes.
24   *
25   * A description of the mail session parameter you find at <a href="https://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html">
26   * https://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html</a>.
27   *
28   * @since 1.3
29   */
30  public final class EmailConstants {
31  
32      /** Charset constant for koi8-r */
33      public static final String KOI8_R = "koi8-r";
34  
35      /** Charset constant for iso-8859-1 */
36      public static final String ISO_8859_1 = StandardCharsets.ISO_8859_1.name();
37  
38      /** Charset constant for us-ascii */
39      public static final String US_ASCII = StandardCharsets.US_ASCII.name();
40  
41      /** Charset constant for utf-8 */
42      public static final String UTF_8 = StandardCharsets.UTF_8.name();
43  
44      /** The debug mode to be used. */
45      public static final String MAIL_DEBUG = "mail.debug";
46  
47      /** The host name of the mail server. */
48      public static final String MAIL_HOST = "mail.smtp.host";
49  
50      /** The port number of the mail server. */
51      public static final String MAIL_PORT = "mail.smtp.port";
52  
53      /** The email address to use for SMTP MAIL command. */
54      public static final String MAIL_SMTP_FROM = "mail.smtp.from";
55  
56      /** If set to true, tries to authenticate the user using the AUTH command. */
57      public static final String MAIL_SMTP_AUTH = "mail.smtp.auth";
58  
59      /** The SMTP user name. */
60      public static final String MAIL_SMTP_USER = "mail.smtp.user";
61  
62      /** The SMTP password. */
63      public static final String MAIL_SMTP_PASSWORD = "mail.smtp.password";
64  
65      /** Specifies the default transport protocol */
66      public static final String MAIL_TRANSPORT_PROTOCOL = "mail.transport.protocol";
67  
68      /** The value to use SMTP as transport protocol */
69      public static final String SMTP = "smtp";
70  
71      /** Defines the text/html content type */
72      public static final String TEXT_HTML = "text/html";
73  
74      /** Defines the html subtype */
75      public static final String TEXT_SUBTYPE_HTML = "html";
76  
77      /** Defines the text/plain content type */
78      public static final String TEXT_PLAIN = "text/plain";
79  
80      /////////////////////////////////////////////////////////////////////////
81      // since 1.1
82      /////////////////////////////////////////////////////////////////////////
83  
84      /**
85       * Indicates if the STARTTLS command shall be used to initiate a TLS-secured connection.
86       *
87       * @since 1.1
88       */
89      public static final String MAIL_TRANSPORT_STARTTLS_ENABLE = "mail.smtp.starttls.enable";
90  
91      /**
92       * Whether to use {@link java.net.Socket} as a fallback if the initial connection fails or not.
93       *
94       * @since 1.1
95       */
96      public static final String MAIL_SMTP_SOCKET_FACTORY_FALLBACK = "mail.smtp.socketFactory.fallback";
97  
98      /**
99       * Specifies the {@link javax.net.SocketFactory} class to create smtp sockets.
100      *
101      * @since 1.1
102      */
103     public static final String MAIL_SMTP_SOCKET_FACTORY_CLASS = "mail.smtp.socketFactory.class";
104 
105     /**
106      * Specifies the port to connect to when using a socket factory.
107      *
108      * @since 1.1
109      */
110     public static final String MAIL_SMTP_SOCKET_FACTORY_PORT = "mail.smtp.socketFactory.port";
111 
112     /**
113      * Socket connection timeout value in milliseconds. Default is infinite timeout.
114      *
115      * @since 1.2
116      */
117     public static final String MAIL_SMTP_CONNECTIONTIMEOUT = "mail.smtp.connectiontimeout";
118 
119     /**
120      * Socket I/O timeout value in milliseconds. Default is infinite timeout.
121      *
122      * @since 1.2
123      */
124     public static final String MAIL_SMTP_TIMEOUT = "mail.smtp.timeout";
125 
126     /**
127      * Default socket timeout.
128      *
129      * @since 1.6.0
130      */
131     public static final Duration SOCKET_TIMEOUT = Duration.ofMinutes(1);
132 
133     /**
134      * If true, requires the use of the STARTTLS command. If the server doesn't support the STARTTLS command, the connection will fail.
135      *
136      * @since 1.3
137      */
138     public static final String MAIL_TRANSPORT_STARTTLS_REQUIRED = "mail.smtp.starttls.required";
139 
140     /**
141      * If set to true, use SSL to connect and use the SSL port by default.
142      *
143      * @since 1.3
144      */
145     public static final String MAIL_SMTP_SSL_ENABLE = "mail.smtp.ssl.enable";
146 
147     /**
148      * If set to true, check the server identity as specified in RFC 2595.
149      *
150      * @since 1.3
151      */
152     public static final String MAIL_SMTP_SSL_CHECKSERVERIDENTITY = "mail.smtp.ssl.checkserveridentity";
153 
154     /**
155      * Specifies the {@link javax.net.ssl.SSLSocketFactory} class to use to create SMTP SSL sockets.
156      *
157      * @since 1.3
158      */
159     public static final String MAIL_SMTP_SSL_SOCKET_FACTORY_CLASS = "mail.smtp.ssl.socketFactory.class";
160 
161     /**
162      * Specifies the port to connect to when using the SMTP SSL socket factory.
163      *
164      * @since 1.3
165      */
166     public static final String MAIL_SMTP_SSL_SOCKET_FACTORY_PORT = "mail.smtp.ssl.socketFactory.port";
167 
168     /////////////////////////////////////////////////////////////////////////
169     // since 1.3.2
170     /////////////////////////////////////////////////////////////////////////
171 
172     /**
173      * If set to true, and a message has some valid and some invalid addresses, send the message anyway, reporting the partial failure with a
174      * SendFailedException. If set to false (the default), the message is not sent to any of the recipients if there is an invalid recipient address.
175      *
176      * @since 1.3.2
177      */
178     public static final String MAIL_SMTP_SEND_PARTIAL = "mail.smtp.sendpartial";
179 
180     /**
181      * If set to true, and a message has some valid and some invalid addresses, send the message anyway, reporting the partial failure with a
182      * SendFailedException. If set to false (the default), the message is not sent to any of the recipients if there is an invalid recipient address.
183      *
184      * @since 1.3.2
185      */
186     public static final String MAIL_SMTPS_SEND_PARTIAL = "mail.smtps.sendpartial";
187 
188     /**
189      * Defines the default mime charset to use when none has been specified for the message.
190      *
191      * @since 1.3.2
192      */
193     public static final String MAIL_MIME_CHARSET = "mail.mime.charset";
194 
195     /////////////////////////////////////////////////////////////////////////
196     // since 1.4
197     /////////////////////////////////////////////////////////////////////////
198 
199     /**
200      * The from email address.
201      *
202      * @since 1.4
203      */
204     public static final String MAIL_FROM = "mail.from";
205 
206     /** Hide constructor. */
207     private EmailConstants() {
208         // do nothing
209     }
210 
211 }