javax.mail

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server GlassFish » mail » javax.mail 
javax.mail
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 included in the download bundle or available on the JavaMail web site.

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 JavaMail API FAQ for answers to the most common questions. The JavaMail web site 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 {@link javax.mail.internet} 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 {@link com.sun.mail.imap IMAP}, {@link com.sun.mail.pop3 POP3}, and {@link com.sun.mail.smtp SMTP} packages provide details.

Java Source File NameTypeComment
Address.javaClass This abstract class models the addresses in a message. Subclasses provide specific implementations.
AuthenticationFailedException.javaClass 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).
Authenticator.javaClass The class Authenticator represents an object that knows how to obtain authentication for a network connection.
BodyPart.javaClass This class models a Part that is contained within a Multipart. This is an abstract class.
EventQueue.javaClass Package private class used by Store & Folder to dispatch events.
FetchProfile.javaClass Clients use a FetchProfile to list the Message attributes that it wishes to prefetch from the server for a range of messages.

Messages obtained from a Folder are light-weight objects that typically start off as empty references to the actual messages. Such a Message object is filled in "on-demand" when the appropriate get*() methods are invoked on that particular Message.

Flags.javaClass The Flags class represents the set of flags on a Message.
Folder.javaClass Folder is an abstract class that represents a folder for mail messages.
FolderClosedException.javaClass 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.
FolderNotFoundException.javaClass This exception is thrown by Folder methods, when those methods are invoked on a non existent folder.
Header.javaClass The Header class stores a name/value pair to represent headers.
IllegalWriteException.javaClass The exception thrown when a write is attempted on a read-only attribute of any Messaging object.
Message.javaClass This class models an email message.
MessageAware.javaInterface An interface optionally implemented by DataSources to supply information to a DataContentHandler about the message context in which the data content object is operating.
MessageContext.javaClass The context in which a piece of Message content is contained.
MessageRemovedException.javaClass The exception thrown when an invalid method is invoked on an expunged Message.
MessagingException.javaClass
MethodNotSupportedException.javaClass
Multipart.javaClass Multipart is a container that holds multiple body parts.
MultipartDataSource.javaInterface MultipartDataSource is a DataSource that contains body parts.
NoSuchProviderException.javaClass This exception is thrown when Session attempts to instantiate a Provider that doesn't exist.
Part.javaInterface The Part interface is the common base interface for Messages and BodyParts.
PasswordAuthentication.javaClass The class PasswordAuthentication is a data holder that is used by Authenticator.
Provider.javaClass The Provider is a class that describes a protocol implementation.
Quota.javaClass This class represents a set of quotas for a given quota root. Each quota root has a set of resources, represented by the Quota.Resource class.
QuotaAwareStore.javaInterface An interface implemented by Stores that support quotas. The QuotaAwareStore.getQuota getQuota and QuotaAwareStore.setQuota setQuota methods support the quota model defined by the IMAP QUOTA extension. Refer to RFC 2087 for more information.
ReadOnlyFolderException.javaClass This exception is thrown when an attempt is made to open a folder read-write access when the folder is marked read-only.
SendFailedException.javaClass This exception is thrown when the message cannot be sent.

The exception includes those addresses to which the message could not be sent as well as the valid addresses to which the message was sent and valid addresses to which the message was not sent.

Service.javaClass An abstract class that contains the functionality common to messaging services, such as stores and transports.
Session.javaClass The Session class represents a mail session and is not subclassed. It collects together properties and defaults used by the mail API's. A single default session can be shared by multiple applications on the desktop.
Store.javaClass An abstract class that models a message store and its access protocol, for storing and retrieving messages.
StoreClosedException.javaClass 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. This exception should be treated as a fatal error; in particular any messaging object belonging to that Store must be considered invalid.
Transport.javaClass An abstract class that models a message transport. Subclasses provide actual implementations.
UIDFolder.javaInterface The UIDFolder interface is implemented by Folders that can support the "disconnected" mode of operation, by providing unique-ids for messages in the folder.
URLName.javaClass The name of a URL.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.