Java Mail (Part 2) - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Java Mail (Part 2)

Description:

The store class models the message database and the access protocol. ... void close(boolean expunge) boolean renameTo(Folder folder) boolean delete(boolean recurse) ... – PowerPoint PPT presentation

Number of Views:140
Avg rating:3.0/5.0
Slides: 28
Provided by: conradh
Category:
Tags: expunge | java | mail | part

less

Transcript and Presenter's Notes

Title: Java Mail (Part 2)


1
Java Mail (Part 2)
Presented By Lalitha Mazimdar March 12, 2001
2
Topics
  • javax.mail.Store
  • javax.mail.Folder
  • javax.mail.search.
  • Packages revisited
  • History
  • Summary
  • Future

3
Javax.mail.Store javax.mail.Folder
The store class models the message database and
the access protocol. Hierarchical storage
structure
4
Retrieve a Store
Just like Transport, there are 5 different ways
of retrieving a Store (or Folder) object via the
Session. Store getStore() Store
getStore(String Protocol) Store
getStore(URLName url) Store getStore(Provider
provider) Folder getFolder(URLName url)
5
Retrieve a Folder
Folder getDefaultFolder() Folder
getFolder(String name)
6
Code to retrieve the Store and Folder
/ Store is retrieved / Store store
session.getStore() / Folder INBOX is
retrieved / Folder inbox
store.getDefaultFolder().getFolder(INBOX)
7
Some Methods in class Folder
boolean exists() boolean create(int type) void
open(int mode) void close(boolean
expunge) boolean renameTo(Folder
folder) boolean delete(boolean recurse)
8
Retrieve a Message
Messages retrieved from Folder
by getMessage(int index) search(SearchTerm
term) Lightweight Message objects
9
Code to Retrieve a Message
void fetchMessages(String filename) Store
store session.getStore(imap) store.connect()
Folder folder store.getDefaultFolder().getFold
er(INBOX) folder.open(Folder.READ_ONLY)
10
int count folder.getMessageCount() for(int
i 0 i lt count i) Message msg
folder.getMessage(i) displayMessage(msg)
folder.close(false) store.close()
//Method ends here
11
Flags
Describe the state of a Message within its
Folder System Flags and user defined flags
12
Javax.mail.search.
BodyTerm(String pattern) FromTerm(Address
address) HeaderTerm(String headername,String
pattern) ReceivedDateTerm(int comparison, Date
date)
13
JavaMail keeps it Simple
Creating a mail message Creating a session
object Sending a mail message Retrieving a
message Executing a high level command
14
Revisiting Packages
Session Message Transport Store Folder
15
Start with the session
The registry allows Service providers to
install providers Clients to use a specific
provider
16
Create a session object with this
information. Create a store object Connect to the
store using a username password
authentication Create a folder object and
retrieve the defaultfolder and the folders
beneath the defaultfolder.
17
Create a singlepart message Create a multipart
message Display the single part messages.
18
Display the multi part messages.
19
Transport the message using static method like
Transport.send(message) Clients can
explicitly instantiate Transport objects.
20
Create a class XYZ implements HttpSessionBindingL
istener This class will have all the code that we
just discussed. Create a JSP that will use this
class XYZ and is also used to control the look
and feel of the mail handling system. !!! That
is it !!!
21
History
Initial prototype started in late 1996 JavaMail
API design started in early 1997 Public review
in late 1997 JavaMail Specification 1.0 FCS on
Dec23, 1997 JavaMail implementation 1.0 FCS
April1, 1998 JavaMail 1.0.1 and 1.0.2 in early
1998 JavaMail 1.1 Specification
and Implementation FCS August 1998 Current
version is 1.1.3
22
Summary
Mail-enable applications easily Allow complex,
innovative uses of Mail technology Fits well
with existing standards, protocols and
implementation Allow for future ideas Simple
things are easy and sophisticated things are
possible
23
Future
A future version of the JavaMail API will provide
support for digitally signed and encrypted
messages. Security features will rely heavily
upon Java 1.2 security features.
24
Thank You !!!
25
Creating a single part message
void createMessage(Session session) MimeMessage
msg new MimeMessage(session) msg.setFrom() msg.
setSubject(The JavaMail API) InternetAddress a
new InternetAddress(abc_at_def.org) msg.setRecip
ient(Message.RecipientType.To, new
InternetAddress(xyz_at_wrox.com) msg.setText(che
ck out the javamail)
26
Creating a multi part message
void createMultipartMessage(Session
session) MimeMessage msg new
MimeMessage(session) //set headers as
before MimeBodyPart bp1 new MimeBodyPart(bp1.set
Text(text in part1 ) MimeBodyPart bp2 new
MimeBodyPart(bp2.setText(text in part2
) MimeMultipart mp new MimiMultipart() mp.add
BodyPart(bp1) mp.addBodyPart(bp2) msg.setContent
(mp)
27
Creating a session
Properties prop System.getProperties() prop.put
(mail.transport.protocol, smtp) prop.put(mai
l.smtp.host, mail.your-isp.com) session
Session.getInstance(prop, null)
//return an array of installed store
protocols Provider prov session.getProviders()
List storeProtocols new ArrayList() for(int
I0 Iltprov.length I) if(provI.getType
Provider.Type.STORE) storeProtocols.add(provI.ge
tProtocol())
Write a Comment
User Comments (0)
About PowerShow.com