uCosminexus Application Server, Application Development Guide
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.
This section describes how to acquire and set up a Session object using 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 |
A mail configuration is acquired using either an annotation or JNDI. Following are both the methods:
// Field variable // Setting up resources using an annotation @Resource(mappedName="TheMailSession") Session session; |
Session session = null; try { javax.naming.InitialContext initial = new javax.naming.InitialContext(); session = (Session) initial.lookup("java:comp/env/TheMailSession"); } catch (javax.naming.NamingException e) { // Resource was not found } |
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); |
All Rights Reserved. Copyright (C) 2012, 2013, Hitachi, Ltd.