Configuring a Mail Session

Very little needs to be configured to get JavaMail up and running. The basis of configuration is a Mail Session, which holds a global set of mail-related properties that define the behavior of the mail client and network. For instance, you could use the Mail Session to configure the transport protocol to be used, or the particular SMTP server or POP3 server to be used. Later, you can override these settings programmatically when you use the Mail Session.

WebLogic publishes the configured Mail Sessions in its JNDI tree. Each Mail Session must be associated with a JNDI nameonce it's deployed, WebLogic makes the Mail Session available to all clients who need to interact with the JavaMail API. A client program simply performs a JNDI lookup to access the Mail Session, optionally overrides a few session properties, and then uses the Mail Session in a standard way according to the JavaMail API. The only WebLogic-specific configuration is for the Mail Session; for this, you must use the Administration Console.

To create a Mail Session, choose the Services/Mail node from the left pane of the Administration Console, and then select the "Configure a new Mail Session" option. Here you need to supply a name for the Mail Session, a JNDI name by which the Mail Session can be accessed, and a list of property/value mappings. These properties adhere to the JavaMail API specification and are listed in Table 9-1.

Table 9-1. JavaMail configuration properties

Property

Description

Default value

mail.store.protocol

This property defines the protocol that should be used to retrieve email.

imap

mail.transport.protocol

This property defines the protocol to be used when sending email.

smtp

mail.host

This property defines the address of the mail server.

localhost

mail..host

This property defines the mail host for a specific protocol. For instance, you can define the host addresses for SMTP and POP3 by creating an entry for mail.smtp.host and mail.pop3.host.

The value of the mail.host property

mail.user

This property defines the name of the default user that is used when retrieving email. Note that JavaMail does not permit the storing of passwords as properties, so you have to specify this programmatically when contacting the mail host.

The value of the user.name Java system property

mail..user

The property defines the name of the default user used for the particular protocol.

The value of the mail.user property

mail.from

This property should be set to the return address of the email and is specified as an email address.

Required

mail.debug

This flag may be set to true to enable output of debugging information.

false

In general, you should set those properties for the Mail Session that you want all clients to inherit by default. For example, if your clients need to use JavaMail to send emails, the following list of property/value pairs should be sufficient for any client of the Mail Session:

mail.from=mountjoy@acme.org mail.transport.protocol=smtp mail.host=smtp.acme.org

Once the Mail Session has been created, you must target it to the server instances that need access to the session.

Категории