Class 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 MailSession object. The properties are always set as strings; the Type column describes how the string is interpreted. For example, use

     props.put("mail.smtp.port", "888");
     
    to set the mail.smtp.port property, 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 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.
    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 MailSession object. The properties are always set as strings; the Type column describes how the string is interpreted. For example, use

     props.put("mail.pop3.port", "888");
     
    to set the mail.pop3.port property, 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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String POP3_CONNECTIONTIMEOUT  
      static java.lang.String POP3_HOST  
      static java.lang.String POP3_PASS  
      static java.lang.String POP3_PORT  
      static java.lang.String POP3_TIMEOUT  
      static java.lang.String POP3_USER  
      static java.lang.String SMTP_AUTH
      If true, attempt to authenticate the user using the AUTH command.
      static java.lang.String SMTP_CONNECTIONTIMEOUT
      Socket connection timeout value in milliseconds.
      static java.lang.String SMTP_FROM
      Email address to use for SMTP MAIL command.
      static java.lang.String SMTP_HOST
      The SMTP server to connect to.
      static java.lang.String SMTP_PASS
      SMTP Password for the default user name.
      static java.lang.String SMTP_PORT
      The SMTP server port to connect to, if the connect() method doesn't explicitly specify one.
      static 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.
      static java.lang.String SMTP_SSL_SOCKET_FACTORY_CLASS
      If set, specifies the name of a class that extends the totalcross.net.ssl.SSLSocketFactory class.
      static 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.
      static java.lang.String SMTP_STARTTLS_REQUIRED
      If true, requires the use of the STARTTLS command.
      static java.lang.String SMTP_TIMEOUT
      Socket I/O timeout value in milliseconds.
      static java.lang.String SMTP_USER
      Default user name for SMTP.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected MailSession()  
    • 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_CONNECTIONTIMEOUT

        public static final java.lang.String POP3_CONNECTIONTIMEOUT
        See Also:
        Constant Field Values
    • Constructor Detail

      • MailSession

        protected MailSession()
    • 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:
        load in class Properties
        Throws:
        IOException