uCosminexus Application Server, Application Development Guide

[Contents][Glossary][Index][Back][Next]

Appendix M.1 Acquiring a Session object

You can acquire or set a Session object either by using or by not using a mail configuration. This section describes both methods of acquiring and setting up a Session object.

Organization of this subsection
(1) When using a mail configuration
(2) When not using a mail configuration

(1) When using a mail configuration

This section describes how to acquire and set up a Session object using a mail configuration.

(a) Settings of a mail configuration

Before you acquire a mail configuration, set the mail configuration and resolve the resource link. For details on mail configuration and resolving the resource link, see 6.3 Mail configuration settings in the uCosminexus Application Server Application Setup Guide. For details on resolving the resource link see 9.3.2 Reference definition of the main configuration in the uCosminexus Application Server Application Setup Guide.

An example of setting the mail configuration is described below. Create the attribute file as follows:

<?xml version="1.0" encoding="MS932"?>
<!DOCTYPE hitachi-mail-property PUBLIC
 '-//Hitachi, Ltd.//DTD Mail Property 7.0//EN'
 'http://localhost/hitachi-mail-property_7_0.dtd'>
<hitachi-mail-property>
  <description>Example of mail property file</description>
  <display-name>TheMailSession</display-name>
  <from>from_address@example.com</from>
  <server>MyMailServer</server>
  <runtime/>
</hitachi-mail-property>

Furthermore, use the attribute setup command of the resource, and register the attribute file as a resource. An example of specifying the command is described below:

cjsetresprop -type mail -resname TheMailSession -c mail.xml
(b) Acquiring a mail configuration

A mail configuration is acquired using either an annotation or JNDI. Following are both the methods:

(2) When not using a mail configuration

When you do not use a mail configuration, you can acquire the Session object with the factory method of the Session class. In this case, as you cannot acquire the items to be set in the mail configuration, you need to specify the settings in the program.

java.util.Properties prop = new java.util.Properties();
// Set up mail.host property.
// Set up other required properties, such as mail.transport.protocol, mail.user, and mail.from.
prop.setProperty("mail.host", "smtp.example.com");
Session session = Session.getInstance(prop);