<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<!-- Generated by javadoc (build 1.6.0_10) on Tue Nov 17 12:13:45 PST 2009 -->
<
META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
Overview (JavaMail API documentation)
<
META NAME="date" CONTENT="2009-11-17">
<
LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
<
SCRIPT type="text/javascript">
function windowTitle()
{
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Overview (JavaMail API documentation)";
}
}
<
BODY BGCOLOR="white" onload="windowTitle();">
<!-- ========= START OF TOP NAVBAR ======= -->
<
A NAME="navbar_top"><!-- --><
/A>
<
A HREF="#skip-navbar_top" title="Skip navigation links"><
/A>
<
TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<
TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<
A NAME="navbar_top_firstrow"><!-- --><
/A>
<
TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<
TR ALIGN="center" VALIGN="top">
<
TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <
FONT CLASS="NavBarFont1Rev"><
B>Overview<
/B><
/FONT> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
FONT CLASS="NavBarFont1">Package<
/FONT> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
FONT CLASS="NavBarFont1">Class<
/FONT> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
FONT CLASS="NavBarFont1">Use<
/FONT> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
A HREF="overview-tree.html"><
FONT CLASS="NavBarFont1"><
B>Tree<
/B><
/FONT><
/A> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
A HREF="deprecated-list.html"><
FONT CLASS="NavBarFont1"><
B>Deprecated<
/B><
/FONT><
/A> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
A HREF="index-files/index-1.html"><
FONT CLASS="NavBarFont1"><
B>Index<
/B><
/FONT><
/A> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
A HREF="help-doc.html"><
FONT CLASS="NavBarFont1"><
B>Help<
/B><
/FONT><
/A> <
/TD>
<
TD ALIGN="right" VALIGN="top" ROWSPAN=3><
EM>
<
TD BGCOLOR="white" CLASS="NavBarCell2"><
FONT SIZE="-2">
PREV
<
TD BGCOLOR="white" CLASS="NavBarCell2"><
FONT SIZE="-2">
<
A HREF="index.html?overview-summary.html" target="_top"><
B>FRAMES<
/B><
/A>
<
A HREF="overview-summary.html" target="_top"><
B>NO FRAMES<
/B><
/A>
<
SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
<
A HREF="allclasses-noframe.html"><
B>All Classes<
/B><
/A>
<
A NAME="skip-navbar_top"><
/A>
<!-- ========= END OF TOP NAVBAR ========= -->
JavaMail API documentation
provides classes that model a mail system.
<
A HREF="#overview_description"><
B>Description<
/B><
/A>
<
TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<
TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<
TH ALIGN="left" COLSPAN="2"><
FONT SIZE="+2">
<
B>JavaMail API Packages<
/B><
/FONT><
/TH>
<
TR BGCOLOR="white" CLASS="TableRowColor">
<
TD WIDTH="20%"><
B><
A HREF="javax/mail/package-summary.html">javax.mail<
/A><
/B><
/TD>
provides classes that model a mail system.<
/TD>
<
TR BGCOLOR="white" CLASS="TableRowColor">
<
TD WIDTH="20%"><
B><
A HREF="javax/mail/event/package-summary.html">javax.mail.event<
/A><
/B><
/TD>
<
TD>Listeners and events
for the JavaMail API.<
/TD>
<
TR BGCOLOR="white" CLASS="TableRowColor">
<
TD WIDTH="20%"><
B><
A HREF="javax/mail/internet/package-summary.html">javax.mail.internet<
/A><
/B><
/TD>
<
TD>Classes specific to Internet mail systems.<
/TD>
<
TR BGCOLOR="white" CLASS="TableRowColor">
<
TD WIDTH="20%"><
B><
A HREF="javax/mail/search/package-summary.html">javax.mail.search<
/A><
/B><
/TD>
<
TD>Message search terms
for the JavaMail API.<
/TD>
<
TR BGCOLOR="white" CLASS="TableRowColor">
<
TD WIDTH="20%"><
B><
A HREF="javax/mail/util/package-summary.html">javax.mail.util<
/A><
/B><
/TD>
<
TD>JavaMail API utility classes.<
/TD>
<
TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<
TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<
TH ALIGN="left" COLSPAN="2"><
FONT SIZE="+2">
<
B>Sun-specific Packages<
/B><
/FONT><
/TH>
<
TR BGCOLOR="white" CLASS="TableRowColor">
<
TD WIDTH="20%"><
B><
A HREF="com/sun/mail/dsn/package-summary.html">com.sun.mail.dsn<
/A><
/B><
/TD>
<
TR BGCOLOR="white" CLASS="TableRowColor">
<
TD WIDTH="20%"><
B><
A HREF="com/sun/mail/imap/package-summary.html">com.sun.mail.imap<
/A><
/B><
/TD>
<
TD>An IMAP protocol provider
for the JavaMail API
that provides access to an IMAP message store.<
/TD>
<
TR BGCOLOR="white" CLASS="TableRowColor">
<
TD WIDTH="20%"><
B><
A HREF="com/sun/mail/pop3/package-summary.html">com.sun.mail.pop3<
/A><
/B><
/TD>
<
TD>A POP3 protocol provider
for the JavaMail API
that provides access to a POP3 message store.<
/TD>
<
TR BGCOLOR="white" CLASS="TableRowColor">
<
TD WIDTH="20%"><
B><
A HREF="com/sun/mail/smtp/package-summary.html">com.sun.mail.smtp<
/A><
/B><
/TD>
<
TD>An SMTP protocol provider
for the JavaMail API
that provides access to an SMTP server.<
/TD>
<
TR BGCOLOR="white" CLASS="TableRowColor">
<
TD WIDTH="20%"><
B><
A HREF="com/sun/mail/util/package-summary.html">com.sun.mail.util<
/A><
/B><
/TD>
<
TD>Utility classes
for use with the JavaMail API.<
/TD>
<
TR BGCOLOR="white" CLASS="TableRowColor">
<
TD WIDTH="20%"><
B><
A HREF="com/sun/mail/util/logging/package-summary.html">com.sun.mail.util.logging<
/A><
/B><
/TD>
facilities.</TD>
</TR>
</TABLE>
<P>
<A NAME="overview_description"><!-- --></A>
<P>
The JavaMail<sup><font size="-2">TM</font></sup> API
provides classes that model a mail system.
The <code>javax.mail</code> package defines classes that are common to
all mail systems.
The <code>javax.mail.internet</code> package defines classes that are specific
to mail systems based on internet standards such as MIME, SMTP, POP3, and IMAP.
The JavaMail API includes the <code>javax.mail</code> package and subpackages.
<P>
For an overview of the JavaMail API, read the JavaMail specification
<A HREF="../../../JavaMail-1.4.pdf" TARGET="_top">
included in the download bundle</A> or
<A HREF="http://java.sun.com/products/javamail/JavaMail-1.4.pdf" TARGET="_top">
available on the JavaMail web site</A>.
<P>
The code to send a plain text message can be as simple as the following:
<PRE>
Properties props = new Properties();
props.put("mail.smtp.host", "my-mail-server");
props.put("mail.from", "me@example.com");
Session session = Session.getInstance(props, null);
try {
MimeMessage msg = new MimeMessage(session);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO,
"you@example.com");
msg.setSubject("JavaMail hello world example");
msg.setSentDate(new Date());
msg.setText("Hello, world!\n");
Transport.send(msg);
} catch (MessagingException mex) {
System.out.println("send failed, exception: " + mex);
}
</PRE>
The JavaMail download bundle contains many more complete examples
in the "demo" directory.
<P>
Don't forget to see the
<
A HREF="http://java.sun.com/products/javamail/FAQ.html" TARGET="_top">
for answers to the most common questions.
The <
A HREF="http://java.sun.com/products/javamail/" TARGET="_top">
contains many additional resources.
The JavaMail API supports the following standard properties,
which may be set in the <
code>Session<
/code>
object, or in the
The properties are always set as strings; the Type column describes
how the string is interpreted. For example, use
props.put("mail.debug", "true");
to set the <
code>mail.debug<
/code> property, which is of
type boolean.
The initial debug mode.
Default is false.
The return email address of the current user, used by the
<
TD>mail.mime.address.strict<
/TD>
The MimeMessage
class uses the <
code>InternetAddress<
/code>
method
<
code>parseHeader<
/code> to parse
headers in messages. This property
controls the strict flag passed to the <
code>parseHeader<
/code>
method. The default is true.
The default host name of the mail server for both Stores and Transports.
Used if the <
code>mail.<
i>protocol<
/i>.host<
/code> property isn
't set.
</TD>
</TR>
<TR>
<TD>mail.store.protocol</TD>
<TD>String</TD>
<TD>
Specifies the default message access protocol. The
<code>Session</code> method <code>getStore()</code> returns a Store
object that implements this protocol. By default the first Store
provider in the configuration files is returned.
</TD>
</TR>
<TR>
<TD>mail.transport.protocol</TD>
<TD>String</TD>
<TD>
Specifies the default message transport protocol. The
<code>Session</code> method <code>getTransport()</code> returns a Transport
object that implements this protocol. By default the first Transport
provider in the configuration files is returned.
</TD>
</TR>
<TR>
<TD>mail.user</TD>
<TD>String</TD>
<TD>
The default user name to use when connecting to the mail server.
Used if the <code>mail.<i>protocol</i>.user</code> property isn't set.
<
TD>mail.<
i>protocol<
/i>.class<
/TD>
Specifies the fully qualified class name of the provider for the
specified protocol. Used in cases where more than one provider
for a given protocol exists; this property can be used to specify
which provider to use by default. The provider must still be listed
in a configuration file.
<
TD>mail.<
i>protocol<
/i>.host<
/TD>
The host name of the mail server for the specified protocol.
Overrides the <
code>mail.host<
/code> property.
<
TD>mail.<
i>protocol<
/i>.port<
/TD>
The port number of the mail server for the specified protocol.
If not specified the protocol's default port number is used.
</TD>
</TR>
<TR>
<TD>mail.<i>protocol</i>.user</TD>
<TD>String</TD>
<TD>
The user name to use when connecting to mail servers
using the specified protocol.
Overrides the <code>mail.user</code> property.
</TD>
</TR>
</TABLE>
<P>
The following properties are supported by Sun's implementation of
JavaMail, but are not currently a required part of the specification.
The names, types, defaults, and semantics of these properties may
change in future releases.
<
TD>mail.transport.protocol.<
i>address-type<
/i><
/TD>
Specifies the default message transport protocol for the specified address type.
Transport object that implements this protocol when the address is of the
specified type (e.g., "rfc822" for standard internet addresses).
By default the first Transport configured for that address type is used.
This property can be used to override the behavior of the
<
A HREF="javax/mail/Transport.html#send(javax.mail.Message)"><
CODE>send<
/CODE><
/A>
method of the
<
A HREF="javax/mail/Transport.html" title="class in javax.mail"><
CODE>Transport<
/CODE><
/A>
class so that
(for example
) the
"smtps"
protocol is used instead of the "smtp" protocol by setting the property
The JavaMail API also supports several System properties;
see the <
A HREF="javax/mail/internet/package-summary.html"><
CODE>javax.mail.internet<
/CODE><
/A> package documentation
for details.
The JavaMail reference
implementation from Sun includes protocol providers in subpackages of
<
code>com.sun.mail<
/code>. Note that the APIs to these protocol
providers are not part of the standard JavaMail API. Portable
programs will not use these APIs.
Nonportable programs may use the APIs of the Sun protocol providers
by
(for example
) casting a returned <
code>Folder<
/code>
object to a
<
code>com.sun.mail.imap.IMAPFolder<
/code>
object. Similarly
for
standard JavaMail APIs.
The Sun protocol providers also support properties that are specific to
those providers. The package documentation for the
<
A HREF="com/sun/mail/imap/package-summary.html"><
CODE>IMAP<
/CODE><
/A>, <
A HREF="com/sun/mail/pop3/package-summary.html"><
CODE>POP3<
/CODE><
/A>,
and <
A HREF="com/sun/mail/smtp/package-summary.html"><
CODE>SMTP<
/CODE><
/A> packages provide details.
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<
A NAME="navbar_bottom"><!-- --><
/A>
<
A HREF="#skip-navbar_bottom" title="Skip navigation links"><
/A>
<
TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<
TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<
A NAME="navbar_bottom_firstrow"><!-- --><
/A>
<
TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<
TR ALIGN="center" VALIGN="top">
<
TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <
FONT CLASS="NavBarFont1Rev"><
B>Overview<
/B><
/FONT> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
FONT CLASS="NavBarFont1">Package<
/FONT> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
FONT CLASS="NavBarFont1">Class<
/FONT> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
FONT CLASS="NavBarFont1">Use<
/FONT> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
A HREF="overview-tree.html"><
FONT CLASS="NavBarFont1"><
B>Tree<
/B><
/FONT><
/A> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
A HREF="deprecated-list.html"><
FONT CLASS="NavBarFont1"><
B>Deprecated<
/B><
/FONT><
/A> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
A HREF="index-files/index-1.html"><
FONT CLASS="NavBarFont1"><
B>Index<
/B><
/FONT><
/A> <
/TD>
<
TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <
A HREF="help-doc.html"><
FONT CLASS="NavBarFont1"><
B>Help<
/B><
/FONT><
/A> <
/TD>
<
TD ALIGN="right" VALIGN="top" ROWSPAN=3><
EM>
<
TD BGCOLOR="white" CLASS="NavBarCell2"><
FONT SIZE="-2">
PREV
<
TD BGCOLOR="white" CLASS="NavBarCell2"><
FONT SIZE="-2">
<
A HREF="index.html?overview-summary.html" target="_top"><
B>FRAMES<
/B><
/A>
<
A HREF="overview-summary.html" target="_top"><
B>NO FRAMES<
/B><
/A>
<
SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
<
A HREF="allclasses-noframe.html"><
B>All Classes<
/B><
/A>
<
A NAME="skip-navbar_bottom"><
/A>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
Copyright &#
169;
2009 <
a href="http://www.sun.com">Sun Microsystems, Inc.<
/a>. All Rights Reserved.