Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2029654
  • 博文数量: 414
  • 博客积分: 10312
  • 博客等级: 上将
  • 技术积分: 4921
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-31 01:49
文章分类

全部博文(414)

文章存档

2011年(1)

2010年(29)

2009年(82)

2008年(301)

2007年(1)

分类: Java

2008-05-18 14:17:06

Package javax.mail

The JavaMailTM API provides classes that model a mail system.

See:
          

Interface Summary
An interface optionally implemented by DataSources to supply information to a DataContentHandler about the message context in which the data content object is operating.
MultipartDataSource is a DataSource that contains body parts.
The Part interface is the common base interface for Messages and BodyParts.
An interface implemented by Stores that support quotas.
The UIDFolder interface is implemented by Folders that can support the "disconnected" mode of operation, by providing unique-ids for messages in the folder.
 

Class Summary
This abstract class models the addresses in a message.
The class Authenticator represents an object that knows how to obtain authentication for a network connection.
This class models a Part that is contained within a Multipart.
Clients use a FetchProfile to list the Message attributes that it wishes to prefetch from the server for a range of messages.
This inner class is the base class of all items that can be requested in a FetchProfile.
The Flags class represents the set of flags on a Message.
This inner class represents an individual system flag.
Folder is an abstract class that represents a folder for mail messages.
The Header class stores a name/value pair to represent headers.
This class models an email message.
This inner class defines the types of recipients allowed by the Message class.
The context in which a piece of Message content is contained.
Multipart is a container that holds multiple body parts.
The class PasswordAuthentication is a data holder that is used by Authenticator.
The Provider is a class that describes a protocol implementation.
This inner class defines the Provider type.
This class represents a set of quotas for a given quota root.
An individual resource in a quota root.
An abstract class that contains the functionality common to messaging services, such as stores and transports.
The Session class represents a mail session and is not subclassed.
An abstract class that models a message store and its access protocol, for storing and retrieving messages.
An abstract class that models a message transport.
A fetch profile item for fetching UIDs.
The name of a URL.
 

Exception Summary
This exception is thrown when the connect method on a Store or Transport object fails due to an authentication failure (e.g., bad user name or password).
This exception is thrown when a method is invoked on a Messaging object and the Folder that owns that object has died due to some reason.
This exception is thrown by Folder methods, when those methods are invoked on a non existent folder.
The exception thrown when a write is attempted on a read-only attribute of any Messaging object.
The exception thrown when an invalid method is invoked on an expunged Message.
The base class for all exceptions thrown by the Messaging classes
The exception thrown when a method is not supported by the implementation
This exception is thrown when Session attempts to instantiate a Provider that doesn't exist.
This exception is thrown when an attempt is made to open a folder read-write access when the folder is marked read-only.
This exception is thrown when the message cannot be sent.
This exception is thrown when a method is invoked on a Messaging object and the Store that owns that object has died due to some reason.
 

Package javax.mail Description

The JavaMailTM API provides classes that model a mail system. The javax.mail package defines classes that are common to all mail systems. The javax.mail.internet 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 javax.mail package and subpackages.

For an overview of the JavaMail API, read the JavaMail specification or .

The code to send a plain text message can be as simple as the following:

    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);
}
The JavaMail download bundle contains many more complete examples in the "demo" directory.

Don't forget to see the for answers to the most common questions. The contains many additional resources.

The JavaMail API supports the following standard properties, which may be set in the Session object, or in the Properties object used to create the Session object. 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 mail.debug property, which is of type boolean.

Name Type Description
mail.debug boolean The initial debug mode. Default is false.
mail.from String The return email address of the current user, used by the InternetAddress method getLocalAddress.
mail.mime.address.strict boolean The MimeMessage class uses the InternetAddress method parseHeader to parse headers in messages. This property controls the strict flag passed to the parseHeader method. The default is true.
mail.host String The default host name of the mail server for both Stores and Transports. Used if the mail.protocol.host property isn't set.
mail.store.protocol String Specifies the default message access protocol. The Session method getStore() returns a Store object that implements this protocol. By default the first Store provider in the configuration files is returned.
mail.transport.protocol String Specifies the default message access protocol. The Session method getTransport() returns a Transport object that implements this protocol. By default the first Transport provider in the configuration files is returned.
mail.user String The default user name to use when connecting to the mail server. Used if the mail.protocol.user property isn't set.
mail.protocol.class String 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.
mail.protocol.host String The host name of the mail server for the specified protocol. Overrides the mail.host property.
mail.protocol.port int The port number of the mail server for the specified protocol. If not specified the protocol's default port number is used.
mail.protocol.user String The user name to use when connecting to mail servers using the specified protocol. Overrides the mail.user property.

The JavaMail API also supports several System properties; see the package documentation for details.

The JavaMail reference implementation from Sun includes protocol providers in subpackages of com.sun.mail. 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 Folder object to a com.sun.mail.imap.IMAPFolder object. Similarly for Store and Message objects returned from the standard JavaMail APIs.

The Sun protocol providers also support properties that are specific to those providers. The package documentation for the , , and packages provide details.

阅读(1583) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~