Javamail properties
JavaMail provides a set of properties that can be used to configure the behavior of the JavaMail API. These properties can be set using the Session
object, which is used to create a JavaMail session.
Here are some common JavaMail properties:
mail.store.protocol
: specifies the protocol to use for storing messages (e.g. POP3, IMAP, etc.)mail.store.host
: specifies the hostname of the mail server for storing messagesmail.store.port
: specifies the port number to use for storing messagesmail.transport.protocol
: specifies the protocol to use for sending messages (e.g. SMTP, etc.)mail.transport.host
: specifies the hostname of the mail server for sending messagesmail.transport.port
: specifies the port number to use for sending messagesmail.debug
: specifies whether to enable debug output (true or false)mail.debug.auth
: specifies whether to enable debug output for authentication (true or false)mail.debug.msgs
: specifies whether to enable debug output for messages (true or false)mail.debug.init
: specifies whether to enable debug output for initialization (true or false)mail.debug.stack
: specifies whether to enable debug output for stack traces (true or false)mail.mime.charset
: specifies the character set to use for decoding MIME messagesmail.mime.decodefile
: specifies whether to decode file attachments (true or false)mail.mime.decodeparameters
: specifies whether to decode MIME parameters (true or false)mail.mime.encodefile
: specifies whether to encode file attachments (true or false)mail.mime.encodeparameters
: specifies whether to encode MIME parameters (true or false)mail.smtp.auth
: specifies whether to use authentication for SMTP (true or false)mail.smtp.starttls.enable
: specifies whether to use STARTTLS for SMTP (true or false)mail.smtp.starttls.required
: specifies whether to require STARTTLS for SMTP (true or false)mail.imap.auth
: specifies whether to use authentication for IMAP (true or false)mail.imap.starttls.enable
: specifies whether to use STARTTLS for IMAP (true or false)mail.imap.starttls.required
: specifies whether to require STARTTLS for IMAP (true or false)
Here is an example of how to set these properties using the Session
object:
Properties props = new Properties();
props.put("mail.store.protocol", "pop3");
props.put("mail.store.host", "pop3.example.com");
props.put("mail.store.port", "110");
props.put("mail.transport.protocol", "smtp");
props.put("mail.transport.host", "smtp.example.com");
props.put("mail.transport.port", "25");
props.put("mail.debug", "true");
Session session = Session.getInstance(props, null);
Note that the Session
object can also be used to set properties for a specific connection, by calling the setProperties()
method on the Store
or Transport
object.