Package totalcross.net.mail
Class MailSession
- java.lang.Object
-
- totalcross.util.Properties
-
- totalcross.net.mail.MailSession
-
public class MailSession extends Properties
Used to store properties used by the messaging API.The SMTP protocol provider supports the following properties, which may be set in the
MailSessionobject. The properties are always set as strings; the Type column describes how the string is interpreted. For example, useprops.put("mail.smtp.port", "888");to set themail.smtp.portproperty, which is of type int.Name Type Description mail.smtp.user String Default user name for SMTP. mail.smtp.password String SMTP Password for the default user name. mail.smtp.host String The SMTP server to connect to. mail.smtp.port int The SMTP server port to connect to, if the connect() method doesn't explicitly specify one. Defaults to 25. mail.smtp.connectiontimeout int Socket connection timeout value in milliseconds. Default is 5000 milliseconds. mail.smtp.timeout int Socket I/O timeout value in milliseconds. Default is 2000 milliseconds. mail.smtp.from String Email address to use for SMTP MAIL command. This sets the envelope return address. Defaults to msg.getFrom()[0] or ConnectionManager.getLocalHost(). NOTE: mail.smtp.user was previously used for this. mail.smtp.auth boolean If true, attempt to authenticate the user using the AUTH command. Defaults to false. mail.smtp.starttls.enable boolean If true, enables the use of the STARTTLScommand (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands. Note that an appropriate trust store must configured so that the client will trust the server's certificate. Defaults to false.mail.smtp.starttls.required boolean If true, requires the use of the STARTTLS command. If the server doesn't support the STARTTLS command, or the command fails, the connect method will fail. Defaults to false. mail.smtp.ssl.port int The SMTP server port to connect to when STARTTLS is enabled, if the connect() method doesn't explicitly specify one. Defaults to 587. mail.smtp.ssl.socketFactory.class String If set, specifies the name of a class that extends the totalcross.net.ssl.SSLSocketFactory class. This class will be used to create SMTP SSL sockets. The POP3 protocol provider supports the following properties, which may be set in the
MailSessionobject. The properties are always set as strings; the Type column describes how the string is interpreted. For example, useprops.put("mail.pop3.port", "888");to set themail.pop3.portproperty, which is of type int.Name Type Description mail.pop3.user String Default user name for POP3. mail.pop3.host String The POP3 server to connect to. mail.pop3.port int The POP3 server port to connect to, if the connect() method doesn't explicitly specify one. Defaults to 110. mail.pop3.connectiontimeout int Socket connection timeout value in milliseconds. Default is infinite timeout. mail.pop3.timeout int Socket I/O timeout value in milliseconds. Default is infinite timeout. - Since:
- TotalCross 1.13
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.util.Properties
Properties.Boolean, Properties.Double, Properties.Int, Properties.Long, Properties.Str, Properties.Value
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPOP3_CONNECTIONTIMEOUTstatic java.lang.StringPOP3_HOSTstatic java.lang.StringPOP3_PASSstatic java.lang.StringPOP3_PORTstatic java.lang.StringPOP3_TIMEOUTstatic java.lang.StringPOP3_USERstatic java.lang.StringSMTP_AUTHIf true, attempt to authenticate the user using the AUTH command.static java.lang.StringSMTP_CONNECTIONTIMEOUTSocket connection timeout value in milliseconds.static java.lang.StringSMTP_FROMEmail address to use for SMTP MAIL command.static java.lang.StringSMTP_HOSTThe SMTP server to connect to.static java.lang.StringSMTP_PASSSMTP Password for the default user name.static java.lang.StringSMTP_PORTThe SMTP server port to connect to, if the connect() method doesn't explicitly specify one.static java.lang.StringSMTP_SSL_PORTThe SMTP server port to connect to when STARTTLS is enabled, if the connect() method doesn't explicitly specify one.static java.lang.StringSMTP_SSL_SOCKET_FACTORY_CLASSIf set, specifies the name of a class that extends the totalcross.net.ssl.SSLSocketFactory class.static java.lang.StringSMTP_STARTTLSIf true, enables the use of the STARTTLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands.static java.lang.StringSMTP_STARTTLS_REQUIREDIf true, requires the use of the STARTTLS command.static java.lang.StringSMTP_TIMEOUTSocket I/O timeout value in milliseconds.static java.lang.StringSMTP_USERDefault user name for SMTP.-
Fields inherited from class totalcross.util.Properties
MAX_PROPS
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMailSession()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MailSessiongetDefaultInstance()Returns a static instance of MailSession, which may be initialized during the application startup.static MailSessiongetInstance()Creates a new empty MailSession.StoregetStore(java.lang.String protocol)Get a Store object that implements the specified protocol.TransportgetTransport(java.lang.String protocol)Get a Transport object that implements the specified protocol.voidload(DataStream ds)Load properties from the given DataStream, but unlike Properties, the contents of the MailSession are not cleared before reading from the DataStream.-
Methods inherited from class totalcross.util.Properties
clear, dumpKeysValues, get, getKeys, load, put, remove, save, size
-
-
-
-
Field Detail
-
SMTP_USER
public static final java.lang.String SMTP_USER
Default user name for SMTP.- See Also:
- Constant Field Values
-
SMTP_PASS
public static final java.lang.String SMTP_PASS
SMTP Password for the default user name.- See Also:
- Constant Field Values
-
SMTP_HOST
public static final java.lang.String SMTP_HOST
The SMTP server to connect to.- See Also:
- Constant Field Values
-
SMTP_PORT
public static final java.lang.String SMTP_PORT
The SMTP server port to connect to, if the connect() method doesn't explicitly specify one. Defaults to 25.- See Also:
- Constant Field Values
-
SMTP_CONNECTIONTIMEOUT
public static final java.lang.String SMTP_CONNECTIONTIMEOUT
Socket connection timeout value in milliseconds. Default is 2000 milliseconds.- See Also:
- Constant Field Values
-
SMTP_TIMEOUT
public static final java.lang.String SMTP_TIMEOUT
Socket I/O timeout value in milliseconds. Default is 5000 milliseconds.- See Also:
- Constant Field Values
-
SMTP_FROM
public static final java.lang.String SMTP_FROM
Email address to use for SMTP MAIL command. This sets the envelope return address. Defaults to msg.getFrom()[0] or ConnectionManager.getLocalHost(). NOTE: mail.smtp.user was previously used for this.- See Also:
- Constant Field Values
-
SMTP_AUTH
public static final java.lang.String SMTP_AUTH
If true, attempt to authenticate the user using the AUTH command. Defaults to false.- See Also:
- Constant Field Values
-
SMTP_STARTTLS
public static final java.lang.String SMTP_STARTTLS
If true, enables the use of the STARTTLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands. Note that an appropriate trust store must configured so that the client will trust the server's certificate. Defaults to false.- See Also:
- Constant Field Values
-
SMTP_STARTTLS_REQUIRED
public static final java.lang.String SMTP_STARTTLS_REQUIRED
If true, requires the use of the STARTTLS command. If the server doesn't support the STARTTLS command, or the command fails, the connect method will fail. Defaults to false.- See Also:
- Constant Field Values
-
SMTP_SSL_PORT
public static final java.lang.String SMTP_SSL_PORT
The SMTP server port to connect to when STARTTLS is enabled, if the connect() method doesn't explicitly specify one. Defaults to 587.- See Also:
- Constant Field Values
-
SMTP_SSL_SOCKET_FACTORY_CLASS
public static final java.lang.String SMTP_SSL_SOCKET_FACTORY_CLASS
If set, specifies the name of a class that extends the totalcross.net.ssl.SSLSocketFactory class. This class will be used to create SMTP SSL sockets.- See Also:
- Constant Field Values
-
POP3_USER
public static final java.lang.String POP3_USER
- See Also:
- Constant Field Values
-
POP3_HOST
public static final java.lang.String POP3_HOST
- See Also:
- Constant Field Values
-
POP3_PORT
public static final java.lang.String POP3_PORT
- See Also:
- Constant Field Values
-
POP3_CONNECTIONTIMEOUT
public static final java.lang.String POP3_CONNECTIONTIMEOUT
- See Also:
- Constant Field Values
-
POP3_TIMEOUT
public static final java.lang.String POP3_TIMEOUT
- See Also:
- Constant Field Values
-
POP3_PASS
public static final java.lang.String POP3_PASS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static MailSession getInstance()
Creates a new empty MailSession.- Returns:
- the new MailSession
- Since:
- TotalCross 1.13
-
getDefaultInstance
public static MailSession getDefaultInstance()
Returns a static instance of MailSession, which may be initialized during the application startup.- Returns:
- the static instance of MailSession.
- Since:
- TotalCross 1.13
-
getStore
public Store getStore(java.lang.String protocol)
Get a Store object that implements the specified protocol. If an appropriate Store object cannot be obtained, null is returned.- Parameters:
protocol-- Returns:
- a Store object, or null if a provider for the given protocol is not found.
- Since:
- TotalCross 1.13
-
getTransport
public Transport getTransport(java.lang.String protocol)
Get a Transport object that implements the specified protocol. If an appropriate Transport object cannot be obtained, null is returned.- Parameters:
protocol-- Returns:
- a Transport object
-
load
public void load(DataStream ds) throws IOException
Load properties from the given DataStream, but unlike Properties, the contents of the MailSession are not cleared before reading from the DataStream.- Overrides:
loadin classProperties- Throws:
IOException
-
-