When you create a mail session, the server-side components and applications are enabled to access JavaMail services with JNDI, using the session properties you assign for them. When creating a mail session, you can designate the mail hosts, the transport and store protocols, and the default mail user so that components that use JavaMail do not have to set these properties. Applications that are heavy email users benefit because GlassFish Server creates a single session object and makes the session available to any component that needs it.
JavaMail settings such as the following can be specified:
JNDI Name. The unique name for the mail session. Use the naming sub-context prefix mail/ for JavaMail resources. For example: mail/MySession
Mail Host. The host name of the default mail server. The connect methods of the store and transport objects use this value if a protocol-specific host property is not supplied. The name must be resolvable to an actual host name.
Default User. The default user name to provide when connecting to a mail server. The connect methods of the store and transport objects use this value if a protocol-specific username property is not supplied.
Default Return Address. The email address of the default user, in the form: username@host.domain.
Description. A descriptive statement for the component.
Session. Indicates whether or not mail session is enabled or disabled at this time
The following topics are addressed here:
Use the create-javamail-resource subcommand in remote mode to create a JavaMail session resource. The JNDI name for a JavaMail session resource customarily includes the mail/ naming subcontext, For example: mail/MyMailSession.
Ensure that the server is running.
Remote subcommands require a running server.
Create a JavaMail resource by using the create-javamail-resource(1) subcommand.
Information about the properties for the subcommand is included in this help page.
To apply your changes, restart GlassFish Server.
See To Restart a Domain.
This example creates a JavaMail resource named mail/MyMailSession. The escape character (\) is used in the --fromaddress option to distinguish the dot (.) and at sign (@).
asadmin> create-javamail-resource --mailhost localhost --mailuser sample --fromaddress sample\@sun\.com mail/MyMailSession Command create-javamail-resource executed successfully. |
You can also view the full syntax and options of the subcommand by typing asadmin help create-javamail-resource at the command line.
Use the list-javamail-resources subcommand in remote mode to list the existing JavaMail session resources.
Ensure that the server is running.
Remote subcommands require a running server.
List the JavaMail resources by using the list-javamail-resources(1) subcommand.
This example lists the JavaMail resources on localhost.
asadmin> list-javamail-resources mail/MyMailSession Command list-javamail-resources executed successfuly. |
You can also view the full syntax and options of the subcommands by typing asadmin help list-javamail-resources at the command line.
List the JavaMail resources by using the list-javamail-resources(1) subcommand.
Modify the values for the specified JavaMail source by using the set(1) subcommand.
The resource is identified by its dotted name.
This example changes joeserver to joe.
asadmin> set server.resources.mail-resource.mail/ MyMailSession.user=joeserver.resources.mail-resource.mail/ MyMailSession.user=joe Command set executed successfully. |
Use the delete-javamail-resource subcommands in remote mode to delete a JavaMail session resource.
References to the specified resource must be removed before running the delete-javamail-resource subcommands.
Ensure that the server is running.
Remote subcommands require a running server.
List the JavaMail resources by using the list-javamail-resources(1) subcommands.
Delete a JavaMail resource by using the delete-javamail-resource(1) subcommands.
To apply your changes, restart GlassFish Server.
See To Restart a Domain.
This example deletes the JavaMail session resource named mail/MyMailSession.
asadmin> delete-javamail-resource mail/MyMailSession Command delete-javamail-resource executed successfully. |
You can also view the full syntax and options of the subcommand by typing asadmin help delete-javamail-resource at the command line.