overview.html revision 292
1178N/A<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
0N/A<HTML>
0N/A<HEAD>
0N/A<!--
0N/A
0N/A DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0N/A
0N/A Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
0N/A
0N/A The contents of this file are subject to the terms of either the GNU
0N/A General Public License Version 2 only ("GPL") or the Common Development
0N/A and Distribution License("CDDL") (collectively, the "License"). You
0N/A may not use this file except in compliance with the License. You can
0N/A obtain a copy of the License at
0N/A https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
0N/A or packager/legal/LICENSE.txt. See the License for the specific
0N/A language governing permissions and limitations under the License.
0N/A
0N/A When distributing the software, include this License Header Notice in each
0N/A file and include the License file at packager/legal/LICENSE.txt.
1178N/A
1178N/A GPL Classpath Exception:
1178N/A Oracle designates this particular file as subject to the "Classpath"
0N/A exception as provided by Oracle in the GPL Version 2 section of the License
0N/A file that accompanied this code.
1178N/A
0N/A Modifications:
0N/A If applicable, add the following below the License Header, with the fields
0N/A enclosed by brackets [] replaced by your own identifying information:
0N/A "Portions Copyright [year] [name of copyright owner]"
0N/A
0N/A Contributor(s):
0N/A If you wish your version of this file to be governed by only the CDDL or
0N/A only the GPL Version 2, indicate your decision by adding "[Contributor]
0N/A elects to include this software in this distribution under the [CDDL or GPL
0N/A Version 2] license." If you don't indicate a single choice of license, a
0N/A recipient has the option to distribute your version of this file under
0N/A either the CDDL, the GPL Version 2 or to extend the choice of license to
0N/A its licensees as provided above. However, if you add GPL Version 2 code
0N/A and therefore, elected the GPL Version 2 license, then the option applies
0N/A only if the new code is made subject to such option by the copyright
0N/A holder.
0N/A
0N/A-->
0N/A
0N/A</HEAD>
0N/A<BODY BGCOLOR="white">
0N/A
0N/AThe JavaMail<sup><font size="-2">TM</font></sup> API
0N/Aprovides classes that model a mail system.
0N/AThe <code>javax.mail</code> package defines classes that are common to
0N/Aall mail systems.
0N/AThe <code>javax.mail.internet</code> package defines classes that are specific
0N/Ato mail systems based on internet standards such as MIME, SMTP, POP3, and IMAP.
0N/AThe JavaMail API includes the <code>javax.mail</code> package and subpackages.
0N/A<P>
1178N/AFor an overview of the JavaMail API, read the JavaMail specification
0N/A<A HREF="/JavaMail-1.4.pdf" TARGET="_top">
0N/Aincluded in the download bundle</A> or
0N/A<A HREF="http://java.sun.com/products/javamail/JavaMail-1.4.pdf" TARGET="_top">
0N/Aavailable on the JavaMail web site</A>.
0N/A<P>
0N/AThe code to send a plain text message can be as simple as the following:
0N/A<PRE>
0N/A Properties props = new Properties();
0N/A props.put("mail.smtp.host", "my-mail-server");
0N/A props.put("mail.from", "me@example.com");
0N/A Session session = Session.getInstance(props, null);
0N/A
0N/A try {
0N/A MimeMessage msg = new MimeMessage(session);
1178N/A msg.setFrom();
0N/A msg.setRecipients(Message.RecipientType.TO,
0N/A "you@example.com");
0N/A msg.setSubject("JavaMail hello world example");
0N/A msg.setSentDate(new Date());
0N/A msg.setText("Hello, world!\n");
0N/A Transport.send(msg);
0N/A } catch (MessagingException mex) {
0N/A System.out.println("send failed, exception: " + mex);
0N/A }
0N/A</PRE>
0N/AThe JavaMail download bundle contains many more complete examples
0N/Ain the "demo" directory.
0N/A<P>
0N/ADon't forget to see the
0N/A<A HREF="http://java.sun.com/products/javamail/FAQ.html" TARGET="_top">
0N/AJavaMail API FAQ</A>
0N/Afor answers to the most common questions.
0N/AThe <A HREF="http://java.sun.com/products/javamail/" TARGET="_top">
0N/AJavaMail web site</A>
0N/Acontains many additional resources.
0N/A<P>
0N/AThe JavaMail API supports the following standard properties,
0N/Awhich may be set in the <code>Session</code> object, or in the
0N/A<code>Properties</code> object used to create the <code>Session</code> object.
0N/AThe properties are always set as strings; the Type column describes
0N/Ahow the string is interpreted. For example, use
0N/A<PRE>
0N/A props.put("mail.debug", "true");
0N/A</PRE>
0N/Ato set the <code>mail.debug</code> property, which is of type boolean.
1178N/A<P>
0N/A<TABLE BORDER>
1178N/A<TR>
1178N/A<TH>Name</TH>
0N/A<TH>Type</TH>
0N/A<TH>Description</TH>
0N/A</TR>
0N/A
0N/A<TR>
0N/A<TD>mail.debug</TD>
0N/A<TD>boolean</TD>
0N/A<TD>
1178N/AThe initial debug mode.
1178N/ADefault is false.
1178N/A</TD>
1178N/A</TR>
1178N/A
1178N/A<TR>
1178N/A<TD>mail.from</TD>
1178N/A<TD>String</TD>
0N/A<TD>
0N/AThe return email address of the current user, used by the
0N/A<code>InternetAddress</code> method <code>getLocalAddress</code>.
0N/A</TD>
0N/A</TR>
0N/A
0N/A<TR>
0N/A<TD>mail.mime.address.strict</TD>
0N/A<TD>boolean</TD>
0N/A<TD>
0N/AThe MimeMessage class uses the <code>InternetAddress</code> method
0N/A<code>parseHeader</code> to parse headers in messages. This property
0N/Acontrols the strict flag passed to the <code>parseHeader</code>
0N/Amethod. The default is true.
0N/A</TD>
0N/A</TR>
0N/A
0N/A<TR>
0N/A<TD>mail.host</TD>
0N/A<TD>String</TD>
0N/A<TD>
0N/AThe default host name of the mail server for both Stores and Transports.
0N/AUsed if the <code>mail.<i>protocol</i>.host</code> property isn't set.
0N/A</TD>
0N/A</TR>
0N/A
1178N/A<TR>
0N/A<TD>mail.store.protocol</TD>
0N/A<TD>String</TD>
1178N/A<TD>
0N/ASpecifies the default message access protocol. The
0N/A<code>Session</code> method <code>getStore()</code> returns a Store
0N/Aobject that implements this protocol. By default the first Store
0N/Aprovider in the configuration files is returned.
0N/A</TD>
0N/A</TR>
0N/A
0N/A<TR>
0N/A<TD>mail.transport.protocol</TD>
0N/A<TD>String</TD>
0N/A<TD>
0N/ASpecifies the default message transport protocol. The
0N/A<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>
</TR>
<TR>
<TD>mail.<i>protocol</i>.class</TD>
<TD>String</TD>
<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>
</TR>
<TR>
<TD>mail.<i>protocol</i>.host</TD>
<TD>String</TD>
<TD>
The host name of the mail server for the specified protocol.
Overrides the <code>mail.host</code> property.
</TD>
</TR>
<TR>
<TD>mail.<i>protocol</i>.port</TD>
<TD>int</TD>
<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.
<P>
<TABLE BORDER>
<TR>
<TH>Name</TH>
<TH>Type</TH>
<TH>Description</TH>
</TR>
<TR>
<TD>mail.transport.protocol.<i>address-type</i></TD>
<TD>String</TD>
<TD>
Specifies the default message transport protocol for the specified address type.
The <code>Session</code> method <code>getTransport(Address)</code> returns a
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
{@link javax.mail.Transport#send send} method of the
{@link javax.mail.Transport Transport} class so that (for example) the "smtps"
protocol is used instead of the "smtp" protocol by setting the property
<code>mail.transport.protocol.rfc822</code> to <code>"smtps"</code>.
</TD>
</TR>
</TABLE>
<P>
The JavaMail API also supports several System properties;
see the {@link javax.mail.internet} package documentation
for details.
<P>
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.
<P>
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
<code>Store</code> and <code>Message</code> objects returned from the
standard JavaMail APIs.
<P>
The Sun protocol providers also support properties that are specific to
those providers. The package documentation for the
{@link com.sun.mail.imap IMAP}, {@link com.sun.mail.pop3 POP3},
and {@link com.sun.mail.smtp SMTP} packages provide details.
</BODY>
</HTML>