Settings for sending a message using javamail.
Full English, classic.
An SMTP protocol provider for the javamail API that provides access to an SMTP server. Refer to RFC 821 for more information.
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 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 thatmail.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 transportsend
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 transportsendMessage
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 transportsend
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();
You'll also need to supply an appropriate realm when using DIGEST-MD5 authentication; your mail server administrator can supply this information. You can set this usingmail.smtp.saslrealm
Property, orsetSASLRealm
Method onSMTPTransport
.
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, usingMimeMultipart
AndMimeMessage
Objects.
See below for the properties to enable these features.
Note also thatThere is not sufficient documentation here to use these features !!!You will need to read the appropriate rfcs mentioned abve 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 have CT it to work.Read the rfcs first !!!
The SMTP protocol Provider supports the following properties, which may be set in the javamailSession
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 setmail.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. |
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. ults to MSG. getfrom () or internetaddress. getlocaladdress (). note: mail. SMTP. user was previusly used for this. |
Mail. SMTP. localhost |
String |
Local host name. defaults to inetaddress. getlocalhost (). gethostname (). shocould not normally need to be set if your JDK and your name service are configured properly. |
Mail. SMTP. EHLO |
Boolean |
If false, do not attempt to sign on with the EHLO command. ults 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. DSN. ipvy |
String |
The specified Y 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 8 bitmime 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. saslrealm |
String |
The realm to use with DIGEST-MD5 authentication. |
Mail. SMTP. quitwait |
Boolean |
If set to true, causes the transport to wait for the response to the quit command. if set to false (the default), The quit command is sent and the connection is immediately closed. (Note: The default may change in the next release .) |
In general, applications shoshould not need to use the classes in this package directly. Instead, they shoshould use the APIS definedjavax.mail
Package (and subpackages). Applications shocould never construct instancesSMTPTransport
Directly. Instead, they shoshould useSession
MethodgetTransport
To acquire an appropriateTransport
Object.