com.sun.mail.smtp

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

Java Source File NameTypeComment
DigestMD5.javaClass DIGEST-MD5 authentication support.
SMTPAddressFailedException.javaClass This exception is thrown when the message cannot be sent.
SMTPAddressSucceededException.javaClass This exception is chained off a SendFailedException when the mail.smtp.reportsuccess property is true.
SMTPMessage.javaClass This class is a specialization of the MimeMessage class that allows you to specify various SMTP options and parameters that will be used when this message is sent over SMTP.
SMTPOutputStream.javaClass In addition to converting lines into the canonical format, i.e., terminating lines with the CRLF sequence, escapes the "." by adding another "." to any "." that appears in the beginning of a line.
SMTPSendFailedException.javaClass This exception is thrown when the message cannot be sent.
SMTPSSLTransport.javaClass This class implements the Transport abstract class using SMTP over SSL for message submission and transport.
SMTPTransport.javaClass This class implements the Transport abstract class using SMTP for message submission and transport.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.