# Specify Mail Resource Dialog Box

You use this dialog box to automatically generate code that sends an e-mail from a Java file. The file must be in an EJB module project or a standard web application project. You cannot generate e-mail code in a free-form web application project.

Element | Description
--- | ---
JNDI Name | The JNDI name of the resource.
Service Locator Strategy | Choose to generate inline lookup code or use an existing service locator. You can click Browse to search for the existing service locator class name.

You use the dialog box as follows:

The IDE creates two methods:

- getSession. Looks up the mail resource and creates a mail session.
- sendMail. Constructs and send the e-mail.

The IDE also registers the resource reference in your module's general deployment descriptor. In your code, call the sendMail method and pass the e-mail address, subject, and body as parameters.

Note: You have to configure the mail resource on the application server yourself. If your project's target server is the GlassFish server, the IDE automatically configures the resource reference in the application-specific deployment descriptor. If you are deploying to a different application server, you have to configure the server-specific deployment descriptors yourself.

Related Topics

Developing Applications with NetBeans IDE,

Copyright © 2016, Oracle and/or its affiliates. All rights reserved.