Introduction
The Java™mail API enables e-mail clients to send and receive e-mail messages from the mail server. The API provides a platform and protocol-independent framework for building java-based e-mail and messaging applications. The JavaMail API is implemented as an optional Java platform package and can also be used as part of the Java 2 Platform Enterprise Edition (ee).
The focus of this article is to build an application using the JavaMail API and then test the program with Ibm®websphere®studio application Developer (hereinafter called Application Developer). This article also provides information about free e-mail servers and JavaMail scenarios.
If you have experience using the JavaMail 1.1 specification, you will be able to create a mail session with an attribute object. However, for JavaMail 1.2, it is best to find a mail session through JNDI instead of creating a new session through the attribute. Depending on the WebSphere V5 InfoCenter, you should always find a mail session.
The Java EE specification regards a mail session instance as a resource or factory from which you can obtain message transfer and storage connections. Do not hard-code the mail session, which is to fill in the attribute object, and then use it to create an instance of Avax.mail.Session.
Application Developer allows you to use JavaMail without any specific file settings. The only thing that needs to be set is the actual mail session resource.
Application developer does not provide a GUI interface for editing message providers and creating mail sessions. You must complete both tasks directly in the WebSphere Admin console. This article will focus on sending e-mail messages that follow the JavaMail specification.
Prerequisite
Make sure that you have an SMTP mail server available-it is usually provided by your ISP, and you can send e-mail through the SMTP mail server. If you do not know any mail server, you can install your own. A free mail server program that you can download is Postcast server, which transforms your machine into an outbound SMTP mail server. For this article, you can use Postcast server instead of the SMTP server from your ISP.
Installing and configuring the postcast SMTP mail server
Download the installation icon.
Double-click the downloaded file and the system should start the Setup wizard.
Click Next on the Welcome page.
Accept the license agreement, and then click Next.
Specify the installation location, and then click Next: