Sending an E-mail from a Java File

See Also

  1. (Optional) Create a service locator class to handle getting the reference to the database.
  2. Open the Java file from which you want to send the e-mail message. The file must be in an EJB module project or a standard web application project. You cannot generate lookup code in a free-form web application project.
  3. In the Source Editor, right-click the file and choose Insert Code > Send E-mail.
  4. Specify the JNDI name of the mail resource on the application server.
  5. Under Service Locator Strategy, specify whether to generate inline lookup code or use an existing service locator. You can click the Browse to search for the service locator class name.
  6. Click OK.

    The IDE creates two methods:

    The IDE also registers the resource reference in your module's general deployment descriptor.

  7. In your code, call the sendMail method and pass the e-mail adress, subject, and body as parameters.

Notes:

See Also
Using a Service Locator
Editing an Enterprise Application's Deployment Descriptors
Configuring EJB Deployment Descriptors

Legal Notices