2010年2月8日 星期一

Using the JavaMail API

Using the JavaMail API
This section defines the syntax and lists the order in which a client
application calls some JavaMail methods in order to access and open a
message located in a folder:
1.A JavaMail client typically begins a mail handling task by obtaining
a JavaMail Session object.
Session session = Session.getInstance(props, authenticator);
2. The client uses the Session object's getStore method to connect to
the default store. The getStore method returns a Store object subclass
that supports the access protocol defined in the user properties
object, which will typically contain per-user preferences.
Store store = session.getStore();
store.connect();
3. If the connection is successful, the client can list available
folders in the Store, and then fetch and view specific Message
objects.
// get the INBOX folder
Folder inbox = store.getFolder("INBOX");
// open the INBOX folder
inbox.open(Folder.READ_WRITE);
Message m = inbox.getMessage(1); // get Message # 1
String subject = m.getSubject(); // get Subject
Object content = m.getContent(); // get content
...
...
4. Finally, the client closes all open folders, and then closes the store.
inbox.close(); // Close the INBOX
store.close(); // Close the Store

--
www.zhouxinxin.com 王不留行

0 评论:

发表评论