ElegantJBeans – Network
Programmers’ Guide
Table of Content
5 Installation and Registration
5.4.2 Using with Graphical User Interface
of IDE
5.4.3 Using directly with source code
6.1.1.1 Creating an instance of
FTPClient
6.1.1.2 Configuring host name and
port
6.1.1.3 Configuring user name and
password
6.1.1.4 Connecting to FTP server
6.1.1.5 Getting file list from
server
6.1.1.6 Getting current working
directory from server
6.1.1.7 Changing working
directory on server
6.1.1.8 Changing to parent
directory on server
6.1.1.9 Making remote directory
on server
6.1.1.10 Removing
remote directory from server
6.1.1.11 Uploading
local file to server
6.1.1.12 Downloading
remote file
6.1.1.15 Disconnecting
from FTP server
6.1.1.16 FTPClient
events and listeners
6.1.2.1 Creating an instance of
HTTPClient
6.1.2.2 Configuring HTTP method
6.1.2.4 Configuring entity body
(string buffer or file)
6.1.2.5 Configuring entity header
6.1.2.6 Configuring HTTP request
general header
6.1.2.7 Configuring HTTP request
header
6.1.2.9 Send request to the
server
6.1.2.10 Getting
response from server
6.1.2.11 Getting
InputStream and OutputStream
6.1.3.1 Creating an instance of
POP3Client
6.1.3.2 Configuring host name and
port
6.1.3.3 Configuring user name and
password
6.1.3.5 Retrieving number of
messages and mail box size
6.1.3.6 Retrieving mail headers
6.1.3.7 Retrieving mail and basic
information regarding mail
6.1.3.8 Retrieving body part of
mail
6.1.3.9 Retrieving attachments
(all or individually)
6.1.3.10 Saving
attachments (all or individually)
6.1.3.12 Deleting
mails from server
6.1.4.1 Creating an instance of
SMTPClient
6.1.4.2 Configuring host name and
port
6.1.4.3 Configuring user name and
password
6.1.4.5 Sending mail with or
without attachment
7 Product and Support Information
This preface describes the document. The preface contains the following sections:
|
Section |
Page |
|
Purpose of this document |
4 |
|
Assumptions |
4 |
|
Document Organization |
4 |
|
Conventions Used |
5 |
The purpose of this document is to provide the fundamental skills necessary to productively install, program, integrate, and use the ElegantJ Network. This document provides both programmer and user perspective to the audience.
This manual assumes that readers are having reasonable level of exposure to fundamentals of Java programming and various architectures.
This document is organized as described in following tables.
Table 1 – Organization of the document
|
Chapter |
Contents |
|
About ElegantJ
Network |
Ø What’s new Ø Toolkit |
|
Features |
Ø ElegantJ Network Beans Ø ElegantJ Other Beans |
|
Product demo |
Ø Installing demo Ø View demo |
|
Installation
and Registration |
Ø Prerequisite Ø Installation Procedure Ø Using with Different IDEs Ø Getting Registered |
|
Programmers’
Guide |
Ø Core components and definitions for different network beans Ø Programmer's guide to frequently asked questions |
|
File |
Italic (slanted) type indicates variable values, instruction operands. |
|
[ | ] |
In syntax definitions, brackets indicate items that are optional and braces indicate items that are required. Vertical bars separating items inside brackets or braces indicate that you choose one item from among those listed. |
|
. . . |
In syntax definitions, a horizontal ellipsis indicates that the preceding item can be repeated one or more times. |
|
Get(1) |
A cross-reference to a reference page includes the appropriate section number in parentheses. For example, get(1) indicates that you can find information on the get command in Section 1 of the reference pages. |
|
// |
An explanation of a particular function performed by preceding code. |
ElegantJ Network offers ready to use network protocol implementation for JAVA based solutions. When you are developing an FTP client, an e-mail client or a socket communication solution or an application that needs FTP capability built into it, ElegantJ Network Beans has a lot to make the development process simpler. The collection includes FTP, HTTP, POP3, SMTP, and MIME complaint message beans to meet your all type of network and communication related needs.
It includes Server, Server Socket, Datagram Packet and Datagram Socket too. The URL bean included in this collection contains powerful methods to get content-encoding, content-expiration, content-length, content-type, content-file. This is the best available collection of off the shelf networking beans for developers.
In case you are using evaluation, an Evaluation Dialog used to popup every 10 minutes. This dialog will now appear only once, making evaluation without interruption.
ElegantJ Network is shipped with following Beans -
Ø ElegantJ FTP client (ftpclient.jar)
Ø ElegantJ HTTP client (httpclient.jar)
Ø ElegantJ POP3 client (pop3client.jar)
Ø ElegantJ SMTP client (smtpclient.jar)
Ø ElegantJ MIME message (message.jar)
Ø ElegantJ Datagram packet (datagrampacket.jar)
Ø ElegantJ Datagram socket (datagramsocket.jar)
Ø ElegantJ Server socket (serversocket.jar)
Ø ElegantJ Socket (socket.jar)
Ø ElegantJ URL (url.jar)
ElegantJ FTPClient Java Bean has functionality of FTP (File Transfer Protocol). Using this JavaBean, one can implement FTP Client functionality very easily.
Ø User can connect to any FTP server.
Ø Host name and port can be customized while connecting to FTP server.
Ø ElegantJ FTPClient JavaBean allows customizable user name and password, while connecting to FTP server.
Ø Work with directory on server - get current directory name, change working directory, create or remove directory on FTP server.
Ø Using ElegantJ FTPClient Java Bean, user can get file list of current working directory from FTP server.
Ø Using ElegantJ FTPClient Java Bean, User can upload a file, download a file, rename a file or remove a file from FTP server.
Ø Provides method to disconnect from FTP server.
ElegantJ HTTPClient Java Bean contains functionality of HTTP (Hyper Text Transfer Protocol) v1.0. One can implement HTTP Client functionality very easily using this JavaBean.
Ø ElegantJ HTTPClient Java Bean supports GET, HEAD and POST methods of HTTP.
Ø You can create and send HTTP requests to HTTP server on the fly.
Ø ElegantJ HTTPClient JavaBean provides method to generate HTTP request by setting fields and values of General Header, Entity Header and Request Headers.
Ø User can post data to a HTTP web server from a string buffer as well as from a file. This Java Bean uses BASE64 encoding while sending data from file.
ElegantJ POP3Client Java Bean has functionality of POP3 (Post Office Protocol v3). This is used to download messages from a POP3 server. Features of POP3Client Java Bean are -
Ø User can set host name and port, while connecting to POP3 server.
Ø User can set user name and password to connect to the POP3 server while connecting.
Ø ElegantJ POP3Client Java Bean can connect to any POP3 server.
Ø User can fetch information about number of mails and mail box size from the server.
Ø This Java Bean has feature to retrieve header information and mail from server.
Ø Facility to delete mail from server itself.
Ø You can explore e-mail fields like TO, CC, From, Subject, Content Type, Date and Body Format.
Ø You can explore body and attachments of mail. About attachments, you can get attachment count, size and file names.
Ø Flexibility to save all the attachments at a time as well as separately.
Ø ElegantJ POP3Client JavaBean includes method to disconnect from POP3 server.
Ø ElegantJ SMTPClient Java Bean has facility to provide Hostname and port name while connecting to SMTP server.
Ø A user name and password that user can set and use, to connect to SMTP server.
Ø This JavaBean can connect to any SMTP Server.
Ø ElegantJ SMTPClient Java Bean provides MIMECompliantMessage to compose a mail, that may or may not have attachments, after composing mail, user can send mail using SMTPClient.
Ø Provides option to save sent messages.
Ø Includes a method to get last status from the client.
Ø This Java Bean includes a method to disconnect from SMTP server.
ElegantJ Message Bean
This Java Bean provides MIME (Multipurpose Internet Mail Extensions) compliant message format. Features are -
Ø ElegantJ Message Java Bean allows single part textual message as well as multipart messages by attaching any type of file with a mail message.
Ø One can set fields of mail message header, like From address, To address, CC address, BCC address, Subject, MIME version, Organization, XMailer and Message Body.
Ø With ElegantJ Message JavaBean you can attach multiple files with the message by a simple method call.
Ø It encodes binary data using BASE64 encoding.
ElegantJ URL Bean
This Java Bean includes functionality of a URL (Uniform Resource Locator). Features are -
Ø ElegantJ URL JavaBean provides methods to get content-encoding, content-expiration, content-length, content-type, content-file of URL contents.
Ø This Java Bean provides methods to get contents of the resource specified by URL and save it as a local file.
ElegantJ Socket Bean
This JavaBean includes client socket. A socket is an endpoint for communication between two computers.
ElegantJ ServerSocket Bean
This Java Bean includes server sockets. A server socket waits for requests to come in over the network. It performs specific operations based on request, and then possibly returns a result to the requester.
ElegantJ DatagramSocket Bean
ElegantJ DatagramSocket
Java Bean includes functionality of a socket for sending and receiving datagram
packets. A datagram socket is the sending or receiving point for a packet
delivery service.
ElegantJ DatagramPacket Bean
This Java Bean includes functionality of datagram packet. Datagram packets are used to implement a connectionless packet delivery service. Each message is routed from one computer to another solely based on information contained within that packet. Multiple packets sent from one machine to another might be routed differently, and might arrive in any order.
Extracted file (archive) contains demos directory. All the demos are located in this demos directory.
Your classpath environment variables must be set correctly in order to run the demos. For windows users we have provided rundemo.bat file which will run demo directly. All Demo Applets contain HTML file to run an Applet associated with it.
For more information on how to set classpath, refer Installation procedure.
FTP client demo application
Description: This is a simple FTP client application. It provides a User Interface window to connect with FTP server and demonstrates almost all FTP client commands.
To run this demo application,
Go to ElegantJNetwork\demos\applications\ftp directory, then execute java -jar ftpclientapp.jar command from command prompt.
HTTP client demo using GET method
Description: Demonstrates HTTP client using HTTP GET method.
To run this demo application,
Go to ElegantJNetwork\demos\applications\http\get directory, then execute java -jar httpclientgetapp.jar command.
HTTP client demo using POST method
Description: Demonstrates HTTP client using HTTP POST method.
To run this demo application
Go to ElegantJNetwork\demos\applications\http\post directory, then execute java -jar httpclientpostapp.jar command.
HTTP client demo using HEAD method
Description: Demonstrates HTTP client using HTTP HEAD method.
To run this demo application,
Go to ElegantJNetwork\demos\applications\http\head directory, then execute java -jar httpclientheadapp.jar command.
POP3 client demo application
Description: Demonstrates POP3 client, which receives pop mail from specified email address, It also explores pop mail with attachments.
To run this demo application,
Go to ElegantJNetwork\demos\applications\pop3 directory, then execute java -jar pop3clientapp.jar command.
SMTP client demo application
Description: Demonstrates SMTP client. It also provides a UI to send mail using SMTP.
To run this demo application,
Go to ElegantJNetwork\demos\applications\smtp directory, then execute java -jar smtpclientapp.jar command.
Note: For windows user we have provided the rundemo.bat file to run demo application.
Before installing ElegantJBeans, please ensure that your computer system and development environment are setup and working as per expectations. Person evaluating ElegantJBeans is expected to be able to write and execute simple JAVA applications.
We provide free pre-purchase technical support to help you complete process of evaluation. Mail to support@elegantJBeans.com for pre-purchase technical support.
To be able to use ElegantJBeans, your computer systems are required to have -
Ø An IDE that supports Java 2 or higher, or
Ø JDK 1.2.2 or higher
Please note that evaluation version of ElegantJBeans cannot be deployed for commercial, non-commercial or any other purpose in any possible way. You may not build any software, applets or applications for distribution with evaluation version of ElegantJBeans.
This evaluation version is to be solely used by you to evaluate suitability of ElegantJbeans for your needs. For more details please go through License Agreement.
On extracting ejnetwork_v1.zip, following directories will be created inside ElegantJNetwork directory -
Directory [jars] contains Jar file(s)
Directory [demos] contains demo application(s) with source code
Directory [docs] contains path for document(s) access
Installing on Windows 95/98
To include ElegantJ Beanery in CLASSPATH, add following statement to your autoexec.bat file,
set CLASSPATH= %CLASSPATH%;C:\ELEGANTJ\<ELEGANTJ_BENARY_HOME>
\jars\<ELEGANTJ_BEAN>.jar;
Restart Windows to make changes effective.
Installing on Windows NT / 2000
Go to Control Panel and select System. You will find environment variables on Environment tab in Windows NT systems and on Advanced tab in Windows 2000 systems.
Find CLASSPATH environment variable or create it.
To include ElegantJ Beanary in the CLASSPATH, specify or add following value for variable -
[EXISTING-CLASSES];C:\<ELEGANTJ_BEANARY_HOME>\jars\<ELEGANTJ_BEAN>.jar
Installing on UNIX / Linux
Before you begin using ElegantJ Beanary, you must manually configure CLASSPATH environment variable. CLASSPATH must point to the location of classes and installation directory.
For example, to set CLASSPATH for ElegantJ Beanary,
setenv CLASSPATH .:/usr/local/<ELEGANTJ_BEANARY_HOME>/jars/
<ELEGANTJ_BEAN>.jar:
If you are using Bourne Shell, commands are,
CLASSPATH= $CLASSPATH:.:/usr/local/<ELEGANTJ_BEANARY_HOME>/jars/
<ELEGANTJ_BEAN>.jar:export CLASSPATH
Follow the steps given below to create a new category and install Bean into Borland JBuilder.
Create a New Category
Ø Click menu Tools > Configure Palette. It opens Palette Properties dialog box.
Ø Click Add button. It opens Add Page Dialog box. Specify name (for example ElegantJ) and click OK. New Category gets created.
Create New Library and Install / Import Bean
Ø On Palette Properties dialog box, click Pages tab. Select Newly created page (for example ElegantJ).
Ø Click button Select Library. Select a Different Library dialog box opens.
Ø Click New button on Select a Different Library dialog box. New Library Wizard dialog box opens.
Ø Specify name for library and click Add button. Select One or More Directory dialog box opens.
Ø Select directory where jar files are located, or select jar file to be imported. Click OK. Dialog box gets closed and New Library Wizard dialog box appears in front.
Ø Click OK on New Library Wizard. It opens Select a Different Library dialog box.
Ø Confirm that newly created library is selected. Click OK. It opens Add Components under Palette Properties.
Ø Click Add from Selected Libraries button. It opens Results dialog box, click OK.
Ø Results dialog box disappears. Click OK on Palette Properties dialog box.
Ø Beans are ready to use.
Follow the steps given below to import ElegantJBeans in Oracle JDeveloper.
To Import beans into a project
Ø Click menu Project > Project Settings. It opens Project Settings dialog box.
Ø Click Libraries entry appearing on the pane on left side.
Ø Click New button. It opens New Library dialog box.
Ø In Library Name entry box, specify Library name. In Location entry box, specify location where you want the library to be located. In Class Path entry box, specify path of jar file of Bean. Browse the location by clicking Edit... button if required.
Ø Click OK. The library you selected appears in Available Libraries list of Project Properties dialog box.
Ø Select the library you want and click > button to add it to Selected Libraries list.
Ø Click menu Tools > Configure Component Palette. It opens Configure Component Palette dialog box.
Ø To create a new palette page, click New Page... button. It opens New Palette Page dialog box. Specify Page Name and Page Type. Click OK. A new page with specified name will be created.
To add component to page
Ø On Configure Component dialog box, from Pages list, select the page and click Add Component button. It opens Add JavaBeans dialog box with available libraries.
Ø Select a library from Library combo box.
Ø Browse the hierarchy and select a component. It displays preview of icon for selected component. Click OK. It shows Palette Confirmation dialog box.
Ø Click Yes on Palette Confirmation dialog box to complete the process.
Ø Beans are ready to use.
You can purchase a license from our web site www.elegantJBeans.com
You can also contact our sales team sales@elegantJBeans.com
On purchasing a license, you will receive a mail having your license key.
License key can be applied to ElegantJ Java Bean using any of the following ways,
Ø Using with Graphical User Interface of IDE
Ø Using directly with source code
While Designing an application or an applet graphically in an Integrated Development Environment, you will find a property named licensekey along with other properties of the bean. Specify key (serial number) in LicenseKey Property.
Note: Instead of typing the
license key, we suggest you to copy the license key from mail and paste it at
required place. Make sure that the
selection does not have any leading or trailing spaces.
When you use the Bean within code, you need to set the key by providing value in setLicenseKey Method.
Note: Instead of typing the
license key, we suggest you to copy the license key from mail and paste it at
required place. Make sure that the
selection does not have leading or trailing spaces.
ClassName object = new ClassName();
object.setLicenseKey("LICENSE_KEY");
Example
AWTTree awtTree = new AWTTree();
awtTree.setLicenseKey("LICENSE_KEY");
6.1.1.1 Creating an instance of FTPClient
Ø To create an instance of ElegantJ FTPClient,
com.elegantj.net.ftp.FTPClient ftpClient = new
com.elegantj.net.http.FTPClient();
This creates an instance of FTPClient.
6.1.1.2 Configuring host name and port
Ø To configure host name
String hostName = "localhost";
ftpClient.setHostName(hostName);
This sets host name to "localhost".
Ø To configure port
int port = 21;
ftpClient.setPort(port);
This sets port to 21.
6.1.1.3 Configuring user name and password
Ø To set user name
String userName = "user_name";
ftpClient.setUserName(userName);
This sets user name.
Ø To set password
String password = "password";
ftpClient.setPassword(password);
This sets password.
6.1.1.4 Connecting to FTP server
Ø To connect to FTP server
boolean success = ftpClient.connect();
This connects FTPClient to FTPServer, and returns a boolean value indicating if connection process was successful or not.
6.1.1.5 Getting file list from server
Ø To get file list of current working directory from server
String fileList = ftpClient.getFileList();
This returns list of files in current working directory of server.
6.1.1.6 Getting current working directory from server
Ø To get current working directory from server
String workingDirectory = ftpClient.getCurrentWorkingDirectory();
This returns current working directory of server.
6.1.1.7 Changing working directory on server
Ø To change working directory on server
String changeToDirectoryName = "/user/data";
ftpClient.changeWorkingDirectory(changeToDirectoryName);
This changes working directory of server to "/user/data".
6.1.1.8 Changing to parent directory on server
Ø To change directory to parent directory
ftpClient.changeToParentDirectory();
This changes remote directory to parent directory.
6.1.1.9 Making remote directory on server
Ø To make remote directory on server
ftpClient.makeRemoteDirectory("/user/data/beans");
This creates "beans" directory on server.
6.1.1.10 Removing remote directory from server
Ø To remove remote directory from server
ftpClient.removeRemoteDirectory("/user/data/beans");
This removes directory at specified path on the server.
6.1.1.11 Uploading local file to server
Ø To upload local file to server
String remoteFileName = "/user/data/data.txt";
String localPath = "c:/my_folder/data.txt";
ftpClient.uploadLocalFile(remoteFileName, localPath);
This uploads local file "data.txt" to the server.
6.1.1.12 Downloading remote file
Ø To download remote file
String remotePath = "/user/data/data.txt";
String localPath = "c:/my_folder/data.txt";
ftpClient.downloadRemoteFile(remotePath, localPath);
This downloads remote file and save it to the "c:/my_folder/data.txt".
Ø To rename remote file
String oldPath = "/user/data/data.txt";
String newPath = "/user/data/data2.txt";
ftpClient.renameRemoteFile(oldPath, newPath);
This renames remote file "data.txt" to "data2.txt".
Ø To delete remote file
String remotePath = "/user/data/data2.txt";
ftpClient.deleteRemoteFile(remotePath);
This removes the remote file "data2.txt".
6.1.1.15 Disconnecting from FTP server
Ø To disconnect from FTP server
ftpClient.disconnect();
This disconnects from FTP server.
6.1.1.16 FTPClient events and listeners
ElegantJ FTPClient provides the following Events/Listeners
Ø Listener Name - StatusListener
Ø Listens to - StatusEvent
Ø When it fires - When status of FTPClient is changed.
Adds StatusListener to FTPClient using addStatusListener and implement following method of the com.elegantj.net.ftp.StatusListener -
public void statusChanged(com.elegantj.net.ftp.StatusEvent e);
StatusEvent is fired when status of the FTPClient is changed.
6.1.2.1 Creating an instance of HTTPClient
Ø To create an instance of ElegantJ HTTPClient,
com.elegantj.net.http.HTTPClient httpClient = new
com.elegantj.net.http.HTTPClient();
This creates an instance of HTTPClient.
6.1.2.2 Configuring HTTP method
Permissible values for HTTP methods are,
Ø com.elegantj.net.http.HTTPClient.HTTP_GET_METHOD
Ø com.elegantj.net.http.HTTPClient.HTTP_HEAD_METHOD
Ø com.elegantj.net.http.HTTPClient.HTTP_POST_METHOD
Ø To set an HTTP method
httpClient.setMethod(com.elegantj.net.http.HTTPClient.HTTP_GET_METHOD);
This sets HTTP_GET_METHOD.HTTP method.
Ø To set URL for the HTTPClient
String url = "http://www.elegantjbeans.com/network/featuresall.htm";
httpClient.setURL(url);
This sets URL for HTTPClient.
6.1.2.4 Configuring entity body (string buffer or file)
Ø To set string buffer as entity body
String buffer = "DataToPost DataToPost DataToPost DataToPost DataToPost DataToPost";
this.httpClient.setStringBufferAsEntityBody(buffer);
This sets the string buffer as an entity body.
Ø To set file as entity body
File file = new File("c:/my_folder/data_to_post.txt");
this.httpClient.setFileAsEntityBody(file);
This sets file as an entity body.
Ø To get HTTP request entity body
String entityBody = httpClient.getHTTPRequestEntityBody();
This returns the entity body.
6.1.2.5 Configuring entity header
Ø To set HTTP request header entity property
httpClient.setHTTPRequestEntityHeaderProperty("Content-Encoding", "7bit");
httpClient.setHTTPRequestEntityHeaderProperty("Content-Length",(new Integer(buffer.length())).toString());
httpClient.setHTTPRequestEntityHeaderProperty("Content-Type", "text/plain");
This sets HTTP request entity header property. User can call this method number of times to set more than one header property.
Ø To get HTTP request entity header value for specified property
String from = httpClient.getHTTPRequestEntityHeaderProperty("Content-Encoding");
This returns value for specified property. Same way user can call this method to retrieve value for other properties.
Ø To get entire HTTP request entity header
String generalHeader = httpClient.getHTTPRequestEntityHeader();
This returns entire HTTP request entity header.
Note: Set entity body and entity body header only if HTTP method is POST.
6.1.2.6 Configuring HTTP request general header
Ø To set HTTP request general header
httpClient.setHTTPRequestGeneralHeaderProperty("Date", (new Date()).toString());
This sets HTTP request general header property. User can call this method number of times to set more than one general header property.
Ø To get HTTP request general header value for the specified property
String date = httpClient.getHTTPRequestGeneralHeadeProperty("Date");
This returns value for specified property. Same way user can call this method to retrieve value for other properties.
Ø To get entire HTTP request general header
String generalHeader = httpClient.getHTTPRequestGeneralHeader();
This returns entire HTTP request general header.
6.1.2.7 Configuring HTTP request header
Ø To set HTTP request header property
httpClient.setHTTPRequestHeaderProperty("From", "xyz@elegantj.com");
httpClient.setHTTPRequestHeaderProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)");
This sets HTTP request header property. User can call this method number of times to set more than one header property.
Ø To get HTTP request header value for specified property
String from = httpClient.getHTTPRequestHeadeProperty("From");
This returns value for specified property. Same way user can call this method to retrieve value for other properties.
Ø To get whole HTTP request header
String generalHeader = httpClient.getHTTPRequestHeader();
This returns entire HTTP request header.
Ø To open a connection
boolean success = httpClient.openConnection();
This opens a connection, returns if connection successfully opened or not.
6.1.2.9 Send request to the server
Ø To send a request to server
httpClient.sendRequestToServer();
This sends request to server.
6.1.2.10 Getting response from server
You can use any of following methods to get response from server
Ø getResponseHeaderFromServer
Ø getResponseFromServer
Ø getHTTPResponseHeaderProperty
Ø getHTTPResponseHeader
Ø getHTTPResponseEntityBody
Ø getHTTPResponse
All above methods are described below.
Ø To get response header from server
httpClient.getResponseHeaderFromServer();
This gets response header from server.
Ø To get response from server
httpClient.getResponseFromServer();
This gets response from server.
Ø To get HTTP response header property
String field = "field_name";
httpClient.getHTTPResponseHeaderProperty(field);
This retrieves an HTTP response header property value.
Ø To get HTTP whole response header
String responseHeader = httpClient.getHTTPResponseHeader();
This retrieves entire response header.
Ø To get HTTP response entity body
byte[] entityBody = httpClient.getHTTPResponseEntityBody();
This retrieves the response entity body.
Ø To get HTTP response
String response = httpClient.getHTTPResponse();
This retrieves the HTTP response.
6.1.2.11 Getting InputStream and OutputStream
Ø To get InputStream
java.io.DataInputStream dataInputStream = httpClient.getInputStream();
This returns input stream.
Ø To get OutputStream
java.io.OutputStream outputStream = httpClient.getOutputStream();
This returns output stream.
Ø To close connection
httpClient.closeConnection();
This closes connection.
6.1.3.1 Creating an instance of POP3Client
Ø To create an instance of ElegantJ POP3Client,
com.elegantj.net.pop3.POP3Client pop3Client = new com.elegantj.net.smtp.POP3Client();
This creates an instance of POP3Client.
6.1.3.2 Configuring host name and port
To configure host name and port of machine on which POP3 service is running,
Ø To set host name
pop3Client.setHostName("localhost");
This sets POP3 host name to localhost.
Ø To set port
pop3Client.setPort(110);
This sets POP3 port to 110.
6.1.3.3 Configuring user name and password
POP3 service authenticates the user before establishing client - server connection.
Ø To set user name
String userName = "user_name";
pop3Client.setUserName(userName);
This sets user name.
Ø To set password
String password = "password";
pop3Client.setPassword(password);
This sets password.
Use openConnection method to open a connection.
Ø To open connection
pop3Client.openConnection();
This opens connection.
6.1.3.5 Retrieving number of messages and mail box size
Ø To retrieve no. of message
int noOfMessages = pop3Client.getNoOfMessages();
This retrieves number (count) of messages.
Ø To retrieve mail box size
int mailBoxSize = pop3Client.getMailBoxSize();
This retrieves mailbox size.
6.1.3.6 Retrieving mail headers
Ø To retrieve mail header
com.elegantj.net.pop3.POP3MessageHeader mailHeader = pop3Client.getMailHeader(0);
This retrieves mail header for 0th mail.
This POP3MessageHeader can be explored using following methods -
Ø Organization
Ø To
Ø From
Ø Subject
Ø CC
Ø ContentTransferEncoding
Ø XMailer
Ø ContentType
Ø MimeVersion
Ø MessageID
Ø Date
Ø XRcptTo
Ø Status
Ø XUIDL
Ø To get organization
String organization = mailHeader.getOrganization();
This retrieves organization from mail header.
Ø To get TO address
String to = mailHeader.getTO();
This retrieves To address from mail header.
Ø To get from address
String from = mailHeader.getFrom();
This retrieves from address from mail header.
Ø To get subject
String subject = mailHeader.getSubject();
This retrieves subject from mail header.
Ø To get CC address
String cc = mailHeader.getCC();
This retrieves the CC address from mail header.
Ø To get content transfer encoding
String contentTransferEncoding = mailHeader.getContentTransferEncoding();
This retrieves content transfer encoding from mail header.
Ø To get XMailer
String xMailer = mailHeader.getXMailer();
This retrieves the XMailer from mail header.
Ø To get content type
String contentType = mailHeader.getContentType();
This retrieves content type from mail header.
Ø To get mime version
String mimeVersion = mailHeader.getMimeVersion();
This retrieves mime version from mail header.
Ø To get message id
String messageID = mailHeader.getMessageID();
This retrieves messageID from mail header.
Ø To get date
String date = mailHeader.getDate();
This retrieves date from the mail header.
Ø To get XRcptTo
String xRcptTo = mailHeader.getXRcptTo();
This retrieves XRcptTo from mail header.
Ø To get status
String status = mailHeader.getStatus();
This retrieves status from mail header.
Ø To get XUIDL
String xUIDL = mailHeader.getXUIDL();
This retrieves the XUIDL.
6.1.3.7 Retrieving mail and basic information regarding mail
Ø To retrieve mail
POP3Message pop3Message = pop3Client.getMail(0);
This retrieves mail (message) at index 0.
This POP3Message can be explored using following methods -
Ø Organization
Ø TO, TO names, TO count, TO name at the specified index
Ø From
Ø Subject
Ø CC, CC names, CC count, CC name at the specified index
Ø ContentTransferEncoding
Ø XMailer
Ø ContentType
Ø MimeVersion
Ø MessageID
Ø Date
Ø XRcptTo
Ø Status
Ø XUIDL
Ø To get Organization
String organization = pop3Message.getOrganization();
This retrieves organization.
Ø To get TO
String to = pop3Message.getTO();
This retrieves TO name.
Ø To get TO names
java.util.Vector toNames = pop3Message.getTONames();
This retrieves TO names.
Ø To get TO count
int toCount = pop3Message.getTOCount();
This retrieves TO count.
Ø To get TO names at a specified index (when there are more than one TO names)
String toName = pop3Message.getTOName(0);
This retrieves TO name at 0th index.
Ø To get CC name
String to = pop3Message.getCC();
This retrieves the CC name.
Ø To get CC names
java.util.Vector ccNames = pop3Message.getCCNames();
This retrieves the CC names.
Ø To get CC count
int ccCount = pop3Message.getCCCount();
This retrieves CC count.
Ø To get CC names at a specified index (in case of more than one CC names)
String ccName = pop3Message.getCCName(0);
This retrieves CC name at the 0th index.
Ø To get content transfer encoding
String contentTransferEncoding = pop3Message.getContentTransferEncoding();
This retrieves content transfer encoding.
Ø To get XMailer
String xMailer = pop3Message.getXMailer();
This retrieves XMailer.
Ø To get content type
String contentType = pop3Message.getContentType();
This retrieves content type.
Ø To get mime version
String mimeVersion = pop3Message.getMimeVersion();
This retrieves mime version.
Ø To get message ID
String messageID = pop3Message.getMessageID();
This retrieves message ID.
Ø To get Date
String date = pop3Message.getDate();
This retrieves date.
Ø To get XRcptTo
String xRcptTo = pop3Message.getXRcptTo();
This retrieves XRcptTo.
Ø To get status
String status = pop3Message.getStatus();
This retrieves status.
Ø To get XUIDL
String xUIDL = pop3Message.getXUIDL();
This retrieves XUIDL.
6.1.3.8 Retrieving body part of mail
Ø To get body
String body = pop3Message.getBody();
This retrieves body string.
Ø To get body format
String bodyFormat = pop3Message.getBodyFormat();
This returns one of the text / plain, text / html, multipart / mixed values.
6.1.3.9 Retrieving attachments (all or individually)
Ø To check whether POP3Message contains attachments or not
boolean isContainsAttachments = pop3Message.isContainsAttachments();
This checks if mail contains attachment (s) or not.
Ø To get attachments count (number of attachments)
int attachmentCount = pop3Message.getAttachmentCount();
This retrieves attachment count (number of attachments).
Ø To get all attachment
java.util.Vector attachments = pop3Message.getAttachmentParts();
This retrieves vector of com.elegantj.net.pop3.POP3MessagePart (all attachments).
Ø To get attachment at a specified index
com.elegantj.net.pop3.POP3Message attachmentPart = pop3Message.getAttachmentPart(0);
This retrieves attachment part(com.elegantj.net.pop3.POP3MessagePart) at 0th index.
Ø To get attachment file names
java.util.Vector attachmentFileNames = pop3Message.getAttachmentFileNames();
This retrieves attachment file names.
Ø To get attachment file name at specified index
String attachmentFileName = pop3Message.getAttachmentFileNmae(0);
This retrieves attachment file name at 0th index.
Ø To get attachment size in bytes
int attachmentSize = pop3Message.getAttachmentSize(0);
This retrieves attachment size of the file (in terms of bytes) at 0th index
6.1.3.10 Saving attachments (all or individually)
Ø To check whether POP3Message contains attachments or not
boolean isContainsAttachments = pop3Message.isContainsAttachments();
This checks if mail contains attachment (s) or not.
Ø To get attachments count (number of attachments)
int attachmentCount = pop3Message.getAttachmentCount();
This retrieves attachment count (number of attachments).
Ø To get all attachment
java.util.Vector attachments = pop3Message.getAttachmentParts();
This retrieves vector of com.elegantj.net.pop3.POP3MessagePart (all attachments).
Ø To get attachment at a specified index
com.elegantj.net.pop3.POP3Message attachmentPart = pop3Message.getAttachmentPart(0);
This retrieves attachment part(com.elegantj.net.pop3.POP3MessagePart) at 0th index.
Ø To get attachment file names
java.util.Vector attachmentFileNames = pop3Message.getAttachmentFileNames();
This retrieves attachment file names.
Ø To get attachment file name at specified index
String attachmentFileName = pop3Message.getAttachmentFileNmae(0);
This retrieves attachment file name at 0th index.
Ø To get attachment size in bytes
int attachmentSize = pop3Message.getAttachmentSize(0);
This retrieves attachment size of the file (in terms of bytes) at 0th index
Ø To save whole message (EML file) to specified file path
String filePath = "c:/mails/mai.eml";pop3Message.saveMessage(filePath);
This saves entire message to specified file path.
Ø To write message (EML file) to the outputstream
FileOutputStream fos = new FileOutputStream("c:/mails/mail.eml");
pop3Message.writeMessage(fos);
This writes entire message to the "c:/mails/mail.eml".
6.1.3.12 Deleting mails from server
Ø To deletes mail at specified index from server
pop3Client.deleteMail(0);
This deletes mail at 0th index from server.
Ø To get last status
String status = pop3Client.getStatus();
This retrieves last status.
Ø To close connection
pop3Client.closeConnection();
This closes connection.
6.1.4.1 Creating an instance of SMTPClient
Ø To create an instance of ElegantJ SMTPClient with default constructor,
com.elegantj.net.smtp.SMTPClient smtpClient = new com.elegantj.net.smtp.SMTPClient();
This creates an instance of SMTPClient.
6.1.4.2 Configuring host name and port
To configure host name and port of machine on which SMTP service is running -
Ø To set host name
smtpClient.setHostName("localhost");
This sets SMTP host name to localhost.
Ø To set port
smtpClient.setPort(25);
This sets SMTP port to 25.
6.1.4.3 Configuring user name and password
Some of the SMTP services authenticate the user before establishing the connection between client and server.
ElegantJ SMTP client provides option to turn on / off the feature of authentication.
Ø To turn on the authentication
smtpClient.setAuthentication(true);
This turns on the authentication.
If authentication is true then user name and password are required to connect with SMTP service, user name and password can be set using following methods.
Ø To set user name
String userName = "user_name";
smtpClient.setUserName(userName);
This sets user name.
Ø To set password
String password = "password";
smtpClient.setPassword(password);
This sets password.
Note: SMTP service needs User name and password to authenticate client (user). If authentication is disabled (e.g. authentication is false), then user name and password are not required.
Use openConnection to open an SMTP connection.
Ø To open connection
smtpClient.openConnection();
This opens connection.
6.1.4.5 Sending mail with or without attachment
Using SMTP client, mail can be sent in following ways
Ø To send mail with attachments
com.elegantj.net.message.MIMECompliantMessage message =
new com.elegantj.net.message.MIMECompliantMessage();
String from = "from_address@domain.com";
String to = "to_address@domain.com";
String cc = "cc_address@domain.com";
String bcc = "bcc_address@domain.com";
String subject = "subject of the mail";
String attachments = "c:/txts/temp.txt,c:/images/img.gif,c:/rtfs/data.rtf";
String body = "body text of the mail";
message.setFrom(from);
message.setTo(to);
message.setCc(cc);
message.setBcc(bcc);
message.setSubject(subject);
message.setAttachments(attach);
message.setBody(body);
smtpClient.sendMail(message);
This sends mail with attachments.
Ø To send mail without attachment
com.elegantj.net.message.MIMECompliantMessage message = new com.elegantj.net.message.MIMECompliantMessage();
String from = "from_address@domain.com";
String to = "to_address@domain.com";
String cc = "cc_address@domain.com";
String bcc = "bcc_address@domain.com";
String subject = "subject of the mail";
String body = "body text of the mail";
message.setFrom(from);
message.setTo(to);
message.setCc(cc);
message.setBcc(bcc);
message.setSubject(subject);
message.setBody(body);
smtpClient.sendMail(message);
This sends mail without attachments.
ElegantJ SMTP client provides option to save sent message.
Ø To save sent message
smtpClient.setSaveSentMessages(true);
Turn on feature of saving a sent message.
ElegantJ SMTP client provides following methods to save sent message
Ø saveMessageToSendFile()
Ø saveMessageToFile(String filePath)
Ø saveMessageToSendFile
smtpClient.saveMessageToSendFile();
This method creates file with auto generated name to save mail.
Ø saveMessageToFile(String filePath)
smtpClient.saveMessageToFile("mail.eml");
This method creates file with specified name to save mail.
Ø To retrieve last status
String lastStatus = smtpClient.getStatus();
This retrieves last status.
Ø To close connection
smtpClient.closeConnection();
This closes connection.
Product and Support Information:
Ø You can find more information about ElegantJ Networks and its features on www.ElegantJBeans.com.
Ø Forward your support related mails to support@ElegantJBeans.com.
Ø Forward your sales related mails to sales@ElegantJBeans.com.
Feedback and Suggestions:
Ø We will be pleased to get your feedback as well as suggestions about our product.
Ø Forward any feedback or suggestions related mails to support@ElegantJBeans.com.