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 
glassfish: mail
License:
URL:https://glassfish.dev.java.net//
Description:
Package NameComment
com.sun.mail.dsn Support for creating and parsing Delivery Status Notifications. Refer to RFC 3462 and RFC 3464 for more information.

A Delivery Status Notification is a MIME message with a Content-Type of multipart/report. A {@link com.sun.mail.dsn.MultipartReport MultipartReport} object represents the content of such a message. The MultipartReport object contains several parts that represent the information in a delivery status notification. The first part is usually a text/plain part that describes the reason for the notification. The second part is a message/delivery-status part, which is represented by a {@link com.sun.mail.dsn.DeliveryStatus DeliveryStatus} object, and contains details about the notification. The third part is either an entire copy of the original message that is returned, represented by a {@link javax.mail.internet.MimeMessage MimeMessage} object, or just the headers of the original message, represented by a {@link com.sun.mail.dsn.MessageHeaders MessageHeaders} object.

To use the classes in this package, include dsn.jar in your class path.

WARNING: The APIs unique to this package should be considered EXPERIMENTAL. They may be changed in the future in ways that are incompatible with applications using the current APIs.

com.sun.mail.handlers
com.sun.mail.iap
com.sun.mail.imap An IMAP protocol provider for the JavaMail API that provides access to an IMAP message store. Both the IMAP4 and IMAP4rev1 protocols are supported. Refer to RFC 2060 for more information.

The IMAP protocol provider can use SASL (RFC 2222) authentication mechanisms on systems that support the javax.security.sasl APIs, such as J2SE 5.0. In addition to the SASL mechanisms that are built into the SASL implementation, users can also provide additional SASL mechanisms of their own design to support custom authentication schemes. See the Java SASL API Programming and Deployment Guide for details. Note that the current implementation doesn't support SASL mechanisms that provide their own integrity or confidentiality layer.

A connected IMAPStore maintains a pool of IMAP protocol objects for use in communicating with the IMAP server. The IMAPStore will create the initial AUTHENTICATED connection and seed the pool with this connection. As folders are opened and new IMAP protocol objects are needed, the IMAPStore will provide them from the connection pool, or create them if none are available. When a folder is closed, its IMAP protocol object is returned to the connection pool if the pool is not over capacity.

A mechanism is provided for timing out idle connection pool IMAP protocol objects. Timed out connections are closed and removed (pruned) from the connection pool.

The connected IMAPStore object may or may not maintain a separate IMAP protocol object that provides the store a dedicated connection to the IMAP server. This is provided mainly for compatibility with previous implementations of the IMAP protocol provider.

The IMAP protocol provider supports the following properties, which may be set in the JavaMail Session object. The properties are always set as strings; the Type column describes how the string is interpreted. For example, use

	props.put("mail.imap.port", "888");
to set the mail.imap.port property, which is of type int.

Name Type Description
mail.imap.user String Default user name for IMAP.
mail.imap.host String The IMAP server to connect to.
mail.imap.port int The IMAP server port to connect to, if the connect() method doesn't explicitly specify one. Defaults to 143.
mail.imap.partialfetch boolean Controls whether the IMAP partial-fetch capability should be used. Defaults to true.
mail.imap.fetchsize int Partial fetch size in bytes. Defaults to 16K.
mail.imap.connectiontimeout int Socket connection timeout value in milliseconds. Default is infinite timeout.
mail.imap.timeout int Socket I/O timeout value in milliseconds. Default is infinite timeout.
mail.imap.statuscachetimeout int Timeout value in milliseconds for cache of STATUS command response. Default is 1000 (1 second). Zero disables cache.
mail.imap.appendbuffersize int Maximum size of a message to buffer in memory when appending to an IMAP folder. If not set, or set to -1, there is no maximum and all messages are buffered. If set to 0, no messages are buffered. If set to (e.g.) 8192, messages of 8K bytes or less are buffered, larger messages are not buffered. Buffering saves cpu time at the expense of short term memory usage. If you commonly append very large messages to IMAP mailboxes you might want to set this to a moderate value (1M or less).
mail.imap.connectionpoolsize int Maximum number of available connections in the connection pool. Default is 1.
mail.imap.connectionpooltimeout int Timeout value in milliseconds for connection pool connections. Default is 45000 (45 seconds).
mail.imap.separatestoreconnection boolean Flag to indicate whether to use a dedicated store connection for store commands. Default is false.
mail.imap.allowreadonlyselect boolean If false, attempts to open a folder read/write will fail if the SELECT command succeeds but indicates that the folder is READ-ONLY. This sometimes indicates that the folder contents can'tbe changed, but the flags are per-user and can be changed, such as might be the case for public shared folders. If true, such open attempts will succeed, allowing the flags to be changed. The getMode method on the Folder object will return Folder.READ_ONLY in this case even though the open method specified Folder.READ_WRITE. Default is false.
mail.imap.auth.login.disable boolean If true, prevents use of the non-standard AUTHENTICATE LOGIN command, instead using the plain LOGIN command. Default is false.
mail.imap.auth.plain.disable boolean If true, prevents use of the AUTHENTICATE PLAIN command. Default is false.
mail.imap.proxyauth.user String If the server supports the PROXYAUTH extension, this property specifies the name of the user to act as. Authenticate to the server using the administrator's credentials. After authentication, the IMAP provider will issue the PROXYAUTH command with the user name specified in this property.
mail.imap.starttls.enable boolean If true, enables the use of the STARTTLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands. Note that an appropriate trust store must configured so that the client will trust the server's certificate. This feature only works on J2SE 1.4 and newer systems. Default is false.
mail.imap.localaddress String Local address (host name) to bind to when creating the IMAP socket. Defaults to the address picked by the Socket class. Should not normally need to be set, but useful with multi-homed hosts where it's important to pick a particular local address to bind to.
mail.imap.localport int Local port number to bind to when creating the IMAP socket. Defaults to the port number picked by the Socket class.
mail.imap.sasl.enable boolean If set to true, attempt to use the javax.security.sasl package to choose an authentication mechanism for login. Defaults to false.
mail.imap.sasl.mechanisms String A space or comma separated list of SASL mechanism names to try to use.
mail.imap.sasl.authorizationid String The authorization ID to use in the SASL authentication. If not set, the authentication ID (user name) is used.
mail.smtp.sasl.realm String The realm to use with SASL authentication mechanisms that require a realm, such as DIGEST-MD5.
mail.imap.socketFactory.class String If set, specifies the name of a class that implements the javax.net.SocketFactory interface. This class will be used to create IMAP sockets.
mail.imap.socketFactory.fallback boolean If set to true, failure to create a socket using the specified socket factory class will cause the socket to be created using the java.net.Socket class. Defaults to true.
mail.imap.socketFactory.port int Specifies the port to connect to when using the specified socket factory. If not set, the default port will be used.
mail.imap.ssl.protocols string Specifies the SSL protocols that will be enabled for SSL connections. The property value is a whitespace separated list of tokens acceptable to the javax.net.ssl.SSLSocket.setEnabledProtocols method.
mail.imap.ssl.ciphersuites string Specifies the SSL cipher suites that will be enabled for SSL connections. The property value is a whitespace separated list of tokens acceptable to the javax.net.ssl.SSLSocket.setEnabledCipherSuites method.
mail.imap.minidletime int Applications typically call the idle method in a loop. If another thread termiantes the IDLE command, it needs a chance to do its work before another IDLE command is issued. The idle method enforces a delay to prevent thrashing between the IDLE command and regular commands. This property sets the delay in milliseconds. If not set, the default is 10 milliseconds.
mail.imap.enableimapevents boolean Enable special IMAP-specific events to be delivered to the Store's ConnectionListener. If true, unsolicited responses received during the Store's idle method will be sent as ConnectionEvents with a type of IMAPStore.RESPONSE. The event's message will be the raw IMAP response string. By default, these events are not sent. NOTE: This capability is highly experimental and likely will change in future releases.

In general, applications should not need to use the classes in this package directly. Instead, they should use the APIs defined by javax.mail package (and subpackages). Applications should never construct instances of IMAPStore or IMAPFolder directly. Instead, they should use the Session method getStore to acquire an appropriate Store object, and from that acquire Folder objects.

WARNING: The APIs unique to this package should be considered EXPERIMENTAL. They may be changed in the future in ways that are incompatible with applications using the current APIs.

com.sun.mail.imap.protocol
com.sun.mail.pop3 A POP3 protocol provider for the JavaMail API that provides access to a POP3 message store. Refer to RFC 1939 for more information.

The POP3 provider provides a Store object that contains a single Folder named "INBOX". Due to the limitations of the POP3 protocol, many of the JavaMail API capabilities like event notification, folder management, flag management, etc. are not allowed. The corresponding methods throw the MethodNotSupportedException exception; see below for details.

Note that JavaMail does not include a local store into which messages can be downloaded and stored. See our Third Party Products web page for availability of "mbox" and "MH" local store providers.

The POP3 provider is accessed through the JavaMail APIs by using the protocol name "pop3" or a URL of the form "pop3://user:password@host:port/INBOX".

POP3 supports only a single folder named "INBOX".

POP3 supports no permanent flags (see {@link javax.mail.Folder#getPermanentFlags Folder.getPermanentFlags()}). In particular, the Flags.Flag.RECENT flag will never be set for POP3 messages. It's up to the application to determine which messages in a POP3 mailbox are "new". There are several strategies to accomplish this, depending on the needs of the application and the environment:

  • A simple approach would be to keep track of the newest message seen by the application.
  • An alternative would be to keep track of the UIDs (see below) of all messages that have been seen.
  • Another approach is to download all messages into a local mailbox, so that all messages in the POP3 mailbox are, by definition, new.

All approaches will require some permanent storage associated with the client.

POP3 does not support the Folder.expunge() method. To delete and expunge messages, set the Flags.Flag.DELETED flag on the messages and close the folder using the Folder.close(true) method. You cannot expunge without closing the folder.

POP3 does not provide a "received date", so the getReceivedDate method will return null. It may be possible to examine other message headers (e.g., the "Received" headers) to estimate the received date, but these techniques are error-prone at best.

The POP3 provider supports the POP3 UIDL command, see {@link com.sun.mail.pop3.POP3Folder#getUID POP3Folder.getUID()}. You can use it as follows:

if (folder instanceof com.sun.mail.pop3.POP3Folder) {
    com.sun.mail.pop3.POP3Folder pf =
	(com.sun.mail.pop3.POP3Folder)folder;
    String uid = pf.getUID(msg);
    if (uid != null)
	... // use it
}

You can also pre-fetch all the UIDs for all messages like this:

FetchProfile fp = new FetchProfile();
fp.add(UIDFolder.FetchProfileItem.UID);
folder.fetch(folder.getMessages(), fp);

Then use the technique above to get the UID for each message. This is similar to the technique used with the UIDFolder interface supported by IMAP, but note that POP3 UIDs are strings, not integers like IMAP UIDs. See the POP3 spec for details.

The POP3 protocol provider supports the following properties, which may be set in the JavaMail Session object. The properties are always set as strings; the Type column describes how the string is interpreted. For example, use

	props.put("mail.pop3.port", "888");
to set the mail.pop3.port property, which is of type int.

Name Type Description
mail.pop3.user String Default user name for POP3.
mail.pop3.host String The POP3 server to connect to.
mail.pop3.port int The POP3 server port to connect to, if the connect() method doesn't explicitly specify one. Defaults to 110.
mail.pop3.connectiontimeout int Socket connection timeout value in milliseconds. Default is infinite timeout.
mail.pop3.timeout int Socket I/O timeout value in milliseconds. Default is infinite timeout.
mail.pop3.rsetbeforequit boolean Send a POP3 RSET command when closing the folder, before sending the QUIT command. Useful with POP3 servers that implicitly mark all messages that are read as "deleted"; this will prevent such messages from being deleted and expunged unless the client requests so. Default is false.
mail.pop3.message.class String Class name of a subclass of com.sun.mail.pop3.POP3Message. The subclass can be used to handle (for example) non-standard Content-Type headers. The subclass must have a public constructor of the form MyPOP3Message(Folder f, int msgno) throws MessagingException.
mail.pop3.localaddress String Local address (host name) to bind to when creating the POP3 socket. Defaults to the address picked by the Socket class. Should not normally need to be set, but useful with multi-homed hosts where it's important to pick a particular local address to bind to.
mail.pop3.localport int Local port number to bind to when creating the POP3 socket. Defaults to the port number picked by the Socket class.
mail.pop3.apop.enable boolean If set to true, use APOP instead of USER/PASS to login to the POP3 server, if the POP3 server supports APOP. APOP sends a digest of the password rather than the clear text password. Defaults to false.
mail.pop3.socketFactory.class String If set, specifies the name of a class that implements the javax.net.SocketFactory interface. This class will be used to create POP3 sockets.
mail.pop3.socketFactory.fallback boolean If set to true, failure to create a socket using the specified socket factory class will cause the socket to be created using the java.net.Socket class. Defaults to true.
mail.pop3.socketFactory.port int Specifies the port to connect to when using the specified socket factory. If not set, the default port will be used.
mail.pop3.disabletop boolean If set to true, the POP3 TOP command will not be used to fetch message headers. This is useful for POP3 servers that don't properly implement the TOP command, or that provide incorrect information in the TOP command results. Defaults to false.
mail.pop3.forgettopheaders boolean If set to true, the headers that might have been retrieved using the POP3 TOP command will be forgotten and replaced by headers retrieved as part of the POP3 RETR command. Some servers, such as some versions of Microsft Exchange and IBM Lotus Notes, will return slightly different headers each time the TOP or RETR command is used. To allow the POP3 provider to properly parse the message content returned from the RETR command, the headers also returned by the RETR command must be used. Setting this property to true will cause these headers to be used, even if they differ from the headers returned previously as a result of using the TOP command. Defaults to false.

In general, applications should not need to use the classes in this package directly. Instead, they should use the APIs defined by javax.mail package (and subpackages). Applications should never construct instances of POP3Store or POP3Folder directly. Instead, they should use the Session method getStore to acquire an appropriate Store object, and from that acquire Folder objects.

WARNING: The APIs unique to this package should be considered EXPERIMENTAL. They may be changed in the future in ways that are incompatible with applications using the current APIs.

com.sun.mail.smtp An SMTP protocol provider for the JavaMail API that provides access to an SMTP server. Refer to RFC 821 for more information.

When sending a message, detailed information on each address that fails is available in an {@link com.sun.mail.smtp.SMTPAddressFailedException SMTPAddressFailedException} chained off the top level {@link javax.mail.SendFailedException SendFailedException} that is thrown. In addition, if the mail.smtp.reportsuccess property is set, an {@link com.sun.mail.smtp.SMTPAddressSucceededException SMTPAddressSucceededException} will be included in the list for each address that is successful. Note that this will cause a top level {@link javax.mail.SendFailedException SendFailedException} to be thrown even though the send was successful.

The SMTP provider also supports ESMTP (RFC 1651). It can optionally use SMTP Authentication (RFC 2554) using the LOGIN, PLAIN, and DIGEST-MD5 mechanisms (RFC 2592 and RFC 2831).

To use SMTP authentication you'll need to set the mail.smtp.auth property (see below) and provide the SMTP Transport with a username and password when connecting to the SMTP server. You can do this using one of the following approaches:

  • Provide an Authenticator object when creating your mail Session and provide the username and password information during the Authenticator callback.

    Note that the mail.smtp.user property can be set to provide a default username for the callback, but the password will still need to be supplied explicitly.

    This approach allows you to use the static Transport send method to send messages.

  • Call the Transport connect method explicitly with username and password arguments.

    This approach requires you to explicitly manage a Transport object and use the Transport sendMessage method to send the message. The transport.java demo program demonstrates how to manage a Transport object. The following is roughly equivalent to the static Transport send method, but supplies the needed username and password:

    Transport tr = session.getTransport("smtp");
    tr.connect(smtphost, username, password);
    msg.saveChanges();	// don't forget this
    tr.sendMessage(msg, msg.getAllRecipients());
    tr.close();
    

When using DIGEST-MD5 authentication, you'll also need to supply an appropriate realm; your mail server administrator can supply this information. You can set this using the mail.smtp.sasl.realm property, or the setSASLRealm method on SMTPTransport.

SMTP can also optionally request Delivery Status Notifications (RFC 1891). The delivery status will typically be reported using a "multipart/report" (RFC 1892) message type with a "message/delivery-status" (RFC 1894) part. JavaMail does not currently provide direct support for these new MIME types, but you can process them as any other "multipart" or "message" content, using MimeMultipart and MimeMessage objects.

See below for the properties to enable these features.

Note also that THERE IS NOT SUFFICIENT DOCUMENTATION HERE TO USE THESE FEATURES!!! You will need to read the appropriate RFCs mentioned above to understand what these features do and how to use them. Don't just start setting properties and then complain to us when it doesn't work like you expect it to work. READ THE RFCs FIRST!!!

The SMTP protocol provider supports the following properties, which may be set in the JavaMail Session object. The properties are always set as strings; the Type column describes how the string is interpreted. For example, use

	props.put("mail.smtp.port", "888");
to set the mail.smtp.port property, which is of type int.

Name Type Description
mail.smtp.user String Default user name for SMTP.
mail.smtp.host String The SMTP server to connect to.
mail.smtp.port int The SMTP server port to connect to, if the connect() method doesn't explicitly specify one. Defaults to 25.
mail.smtp.connectiontimeout int Socket connection timeout value in milliseconds. Default is infinite timeout.
mail.smtp.timeout int Socket I/O timeout value in milliseconds. Default is infinite timeout.
mail.smtp.from String Email address to use for SMTP MAIL command. This sets the envelope return address. Defaults to msg.getFrom() or InternetAddress.getLocalAddress(). NOTE: mail.smtp.user was previously used for this.
mail.smtp.localhost String Local host name used in the SMTP HELO or EHLO command. Defaults to InetAddress.getLocalHost().getHostName(). Should not normally need to be set if your JDK and your name service are configured properly.
mail.smtp.localaddress String Local address (host name) to bind to when creating the SMTP socket. Defaults to the address picked by the Socket class. Should not normally need to be set, but useful with multi-homed hosts where it's important to pick a particular local address to bind to.
mail.smtp.localport int Local port number to bind to when creating the SMTP socket. Defaults to the port number picked by the Socket class.
mail.smtp.ehlo boolean If false, do not attempt to sign on with the EHLO command. Defaults to true. Normally failure of the EHLO command will fallback to the HELO command; this property exists only for servers that don't fail EHLO properly or don't implement EHLO properly.
mail.smtp.auth boolean If true, attempt to authenticate the user using the AUTH command. Defaults to false.
mail.smtp.submitter String The submitter to use in the AUTH tag in the MAIL FROM command. Typically used by a mail relay to pass along information about the original submitter of the message. See also the {@link com.sun.mail.smtp.SMTPMessage#setSubmitter setSubmitter} method of {@link com.sun.mail.smtp.SMTPMessage SMTPMessage}. Mail clients typically do not use this.
mail.smtp.dsn.notify String The NOTIFY option to the RCPT command. Either NEVER, or some combination of SUCCESS, FAILURE, and DELAY (separated by commas).
mail.smtp.dsn.ret String The RET option to the MAIL command. Either FULL or HDRS.
mail.smtp.allow8bitmime boolean If set to true, and the server supports the 8BITMIME extension, text parts of messages that use the "quoted-printable" or "base64" encodings are converted to use "8bit" encoding if they follow the RFC2045 rules for 8bit text.
mail.smtp.sendpartial boolean If set to true, and a message has some valid and some invalid addresses, send the message anyway, reporting the partial failure with a SendFailedException. If set to false (the default), the message is not sent to any of the recipients if there is an invalid recipient address.
mail.smtp.sasl.realm String The realm to use with DIGEST-MD5 authentication.
mail.smtp.quitwait boolean If set to false, the QUIT command is sent and the connection is immediately closed. If set to true (the default), causes the transport to wait for the response to the QUIT command.
mail.smtp.reportsuccess boolean If set to true, causes the transport to include an {@link com.sun.mail.smtp.SMTPAddressSucceededException SMTPAddressSucceededException} for each address that is successful. Note also that this will cause a {@link javax.mail.SendFailedException SendFailedException} to be thrown from the {@link com.sun.mail.smtp.SMTPTransport#sendMessage sendMessage} method of {@link com.sun.mail.smtp.SMTPTransport SMTPTransport} even if all addresses were correct and the message was sent successfully.
mail.smtp.socketFactory.class String If set, specifies the name of a class that implements the javax.net.SocketFactory interface. This class will be used to create SMTP sockets.
mail.smtp.socketFactory.fallback boolean If set to true, failure to create a socket using the specified socket factory class will cause the socket to be created using the java.net.Socket class. Defaults to true.
mail.smtp.socketFactory.port int Specifies the port to connect to when using the specified socket factory. If not set, the default port will be used.
mail.smtp.mailextension String Extension string to append to the MAIL command. The extension string can be used to specify standard SMTP service extensions as well as vendor-specific extensions. Typically the application should use the {@link com.sun.mail.smtp.SMTPTransport SMTPTransport} method {@link com.sun.mail.smtp.SMTPTransport#supportsExtension supportsExtension} to verify that the server supports the desired service extension. See RFC 1869 and other RFCs that define specific extensions.
mail.smtp.starttls.enable boolean If true, enables the use of the STARTTLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands. Note that an appropriate trust store must configured so that the client will trust the server's certificate. Defaults to false.
mail.smtp.userset boolean If set to true, use the RSET command instead of the NOOP command in the {@link javax.mail.Transport#isConnected isConnected} method. In some cases sendmail will respond slowly after many NOOP commands; use of RSET avoids this sendmail issue. Defaults to false.
mail.smtp.ssl.protocols string Specifies the SSL protocols that will be enabled for SSL connections. The property value is a whitespace separated list of tokens acceptable to the javax.net.ssl.SSLSocket.setEnabledProtocols method.
mail.smtp.ssl.ciphersuites string Specifies the SSL cipher suites that will be enabled for SSL connections. The property value is a whitespace separated list of tokens acceptable to the javax.net.ssl.SSLSocket.setEnabledCipherSuites method.

In general, applications should not need to use the classes in this package directly. Instead, they should use the APIs defined by javax.mail package (and subpackages). Applications should never construct instances of SMTPTransport directly. Instead, they should use the Session method getTransport to acquire an appropriate Transport object.

WARNING: The APIs unique to this package should be considered EXPERIMENTAL. They may be changed in the future in ways that are incompatible with applications using the current APIs.

com.sun.mail.util
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.

javax.mail.event Listeners and events for the JavaMail API. This package defines listener classes and event classes used by the classes defined in the javax.mail package.
javax.mail.internet Classes specific to Internet mail systems. This package supports features that are specific to Internet mail systems based on the MIME standard (RFC 2045, RFC 2046, and RFC 2047). The IMAP, SMTP, and POP3 protocols use {@link javax.mail.internet.MimeMessage MimeMessages}.

The JavaMail API specification requires support for the following properties, which must be set in the System properties. The properties are always set as strings; the Type column describes how the string is interpreted. For example, use (in J2SE 1.2 and newer)

	System.setProperty("mail.mime.address.strict", "false");
to set the mail.mime.address.strict property, which is of type boolean.

Name Type Description
mail.mime.address.strict boolean The mail.mime.address.strict session property controls the parsing of address headers. By default, strict parsing of address headers is done. If this property is set to "false", strict parsing is not done and many illegal addresses that sometimes occur in real messages are allowed. See the InternetAddress class for details.
mail.mime.charset String The mail.mime.charset System property can be used to specify the default MIME charset to use for encoded words and text parts that don't otherwise specify a charset. Normally, the default MIME charset is derived from the default Java charset, as specified in the file.encoding System property. Most applications will have no need to explicitly set the default MIME charset. In cases where the default MIME charset to be used for mail messages is different than the charset used for files stored on the system, this property should be set.
mail.mime.decodetext.strict boolean The mail.mime.decodetext.strict property controls decoding of MIME encoded words. The MIME spec requires that encoded words start at the beginning of a whitespace separated word. Some mailers incorrectly include encoded words in the middle of a word. If the mail.mime.decodetext.strict System property is set to "false", an attempt will be made to decode these illegal encoded words. The default is true.
mail.mime.encodeeol.strict boolean The mail.mime.encodeeol.strict property controls the choice of Content-Transfer-Encoding for MIME parts that are not of type "text". Often such parts will contain textual data for which an encoding that allows normal end of line conventions is appropriate. In rare cases, such a part will appear to contain entirely textual data, but will require an encoding that preserves CR and LF characters without change. If the mail.mime.encodeeol.strict System property is set to "true", such an encoding will be used when necessary. The default is false.
mail.mime.decodefilename boolean If set to "true", the getFileName method uses the MimeUtility method decodeText to decode any non-ASCII characters in the filename. Note that this decoding violates the MIME specification, but is useful for interoperating with some mail clients that use this convention. The default is false.
mail.mime.encodefilename boolean If set to "true", the setFileName method uses the MimeUtility method encodeText to encode any non-ASCII characters in the filename. Note that this encoding violates the MIME specification, but is useful for interoperating with some mail clients that use this convention. The default is false.
mail.mime.decodeparameters boolean If set to "true", non-ASCII parameters in a ParameterList, e.g., in a Content-Type header, will be encoded as specified by RFC 2231. The default is false.
mail.mime.encodeparameters boolean If set to "true", non-ASCII parameters in a ParameterList, e.g., in a Content-Type header, will be decoded as specified by RFC 2231. The default is false.
mail.mime.multipart. ignoremissingendboundary boolean Normally, when parsing a multipart MIME message, a message that is missing the final end boundary line is not considered an error. The data simply ends at the end of the input. Note that messages of this form violate the MIME specification. If the property mail.mime.multipart.ignoremissingendboundary is set to false, such messages are considered an error and a MesagingException will be thrown when parsing such a message.
mail.mime.multipart. ignoremissingboundaryparameter boolean If the Content-Type header for a multipart content does not have a boundary parameter, the multipart parsing code will look for the first line in the content that looks like a boundary line and extract the boundary parameter from the line. If this property is set to "false", a MessagingException will be thrown if the Content-Type header doesn't specify a boundary parameter. The default is true.

The following properties are supported by Sun's implementation of JavaMail, but are not currently a required part of the specification. As above, these must be set as System properties. The names, types, defaults, and semantics of these properties may change in future releases.

Name Type Description
mail.mime.base64.ignoreerrors boolean If set to "true", the BASE64 decoder will ignore errors in the encoded data, returning EOF. This may be useful when dealing with improperly encoded messages that contain extraneous data at the end of the encoded stream. Note however that errors anywhere in the stream will cause the decoder to stop decoding so this should be used with extreme caution. The default is false.
mail.mime.foldtext boolean If set to "true", header fields containing just text such as the Subject and Content-Description header fields, and long parameter values in structured headers such as Content-Type will be folded (broken into 76 character lines) when set and unfolded when read. The default is true.
mail.mime.setcontenttypefilename boolean If set to "true", the setFileName method will also set the name parameter on the Content-Type header to the specified filename. This supports interoperability with some old mail clients. The default is true.
mail.mime.setdefaulttextcharset boolean When updating the headers of a message, a body part with a text content type but no charset parameter will have a charset parameter added to it if this property is set to "true". The default is true.
mail.mime.applefilenames boolean Apple Mail incorrectly encodes filenames that contain spaces, forgetting to quote the parameter value. If this property is set to "true", JavaMail will try to detect this situation when parsing parameters and work around it. The default is false.
mail.alternates String A string containing other email addresses that the current user is known by. The MimeMessage reply method will eliminate any of these addresses from the recipient list in the message it constructs, to avoid sending the reply back to the sender.
mail.replyallcc boolean If set to "true", the MimeMessage reply method will put all recipients except the original sender in the Cc list of the newly constructed message. Normally, recipients in the To header of the original message will also appear in the To list of the newly constructed message.

javax.mail.search Message search terms for the JavaMail API. This package defines classes that can be used to construct a search expression to search a folder for messages matching the expression; see the {@link javax.mail.Folder#search search} method on {@link javax.mail.Folder javax.mail.Folder}. See {@link javax.mail.search.SearchTerm SearchTerm}.
javax.mail.util Utility classes. This package specifies utility classes that are useful with other JavaMail APIs.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.