|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.mail.Email
public abstract class Email
The base class for all email messages. This class sets the sender's email & name, receiver's email & name, subject, and the sent date. Subclasses are responsible for setting the message body.
Field Summary | |
---|---|
static String |
ATTACHMENTS
|
protected javax.mail.Authenticator |
authenticator
Instance of an Authenticator object that will be used
when authentication is requested from the mail server. |
protected List |
bccList
List of "bcc" email adresses |
protected String |
bounceAddress
Address to which undeliverable mail should be sent. |
protected List |
ccList
List of "cc" email adresses |
protected String |
charset
The charset to use for this message |
protected Object |
content
The content |
static String |
CONTENT_TYPE
|
protected String |
contentType
The content type |
protected boolean |
debug
Set session debugging on or off |
static String |
EMAIL_BODY
|
static String |
EMAIL_SUBJECT
|
protected javax.mail.internet.MimeMultipart |
emailBody
An attachment |
static String |
FILE_SERVER
|
protected javax.mail.internet.InternetAddress |
fromAddress
The Address of the sending party, mandatory |
protected Map |
headers
Used to specify the mail headers. |
protected String |
hostName
The hostname of the mail server with which to connect. |
static String |
ISO_8859_1
|
static String |
KOI8_R
|
static String |
MAIL_DEBUG
|
static String |
MAIL_HOST
|
static String |
MAIL_PORT
|
static String |
MAIL_SMTP_AUTH
|
static String |
MAIL_SMTP_CONNECTIONTIMEOUT
Socket connection timeout value in milliseconds. |
static String |
MAIL_SMTP_FROM
|
static String |
MAIL_SMTP_PASSWORD
|
static String |
MAIL_SMTP_SOCKET_FACTORY_CLASS
|
static String |
MAIL_SMTP_SOCKET_FACTORY_FALLBACK
|
static String |
MAIL_SMTP_SOCKET_FACTORY_PORT
|
static String |
MAIL_SMTP_TIMEOUT
Socket I/O timeout value in milliseconds. |
static String |
MAIL_SMTP_USER
|
static String |
MAIL_TRANSPORT_PROTOCOL
|
static String |
MAIL_TRANSPORT_TLS
|
protected javax.mail.internet.MimeMessage |
message
The email message to send. |
protected boolean |
popBeforeSmtp
Used to determine whether to use pop3 before smtp, and if so the settings. |
protected String |
popHost
the host name of the pop3 server |
protected String |
popPassword
the password to log into the pop3 server |
protected String |
popUsername
the user name to log into the pop3 server |
static String |
RECEIVER_EMAIL
|
static String |
RECEIVER_NAME
|
protected List |
replyList
List of "replyTo" email adresses |
static String |
SENDER_EMAIL
|
static String |
SENDER_NAME
|
protected Date |
sentDate
Sent date |
static String |
SMTP
|
protected String |
smtpPort
The port number of the mail server to connect to. |
protected int |
socketConnectionTimeout
socket connection timeout value in milliseconds |
protected int |
socketTimeout
socket I/O timeout value in milliseconds |
protected boolean |
ssl
does the current transport use SSL encryption? |
protected String |
sslSmtpPort
The port number of the SSL enabled SMTP server; defaults to the standard port, 465. |
protected String |
subject
The Subject |
static String |
TEXT_HTML
|
static String |
TEXT_PLAIN
|
protected boolean |
tls
does server require TLS encryption for authentication |
protected List |
toList
List of "to" email adresses |
static String |
US_ASCII
|
Constructor Summary | |
---|---|
Email()
|
Method Summary | |
---|---|
Email |
addBcc(String email)
Add a blind BCC recipient to the email. |
Email |
addBcc(String email,
String name)
Add a blind BCC recipient to the email using the specified address and the specified personal name. |
Email |
addBcc(String email,
String name,
String charset)
Add a blind BCC recipient to the email using the specified address, personal name, and charset encoding for the name. |
Email |
addCc(String email)
Add a recipient CC to the email. |
Email |
addCc(String email,
String name)
Add a recipient CC to the email using the specified address and the specified personal name. |
Email |
addCc(String email,
String name,
String charset)
Add a recipient CC to the email using the specified address, personal name, and charset encoding for the name. |
void |
addHeader(String name,
String value)
Adds a header ( name, value ) to the headers Map. |
Email |
addReplyTo(String email)
Add a reply to address to the email. |
Email |
addReplyTo(String email,
String name)
Add a reply to address to the email using the specified address and the specified personal name. |
Email |
addReplyTo(String email,
String name,
String charset)
Add a reply to address to the email using the specified address, personal name, and charset encoding for the name. |
Email |
addTo(String email)
Add a recipient TO to the email. |
Email |
addTo(String email,
String name)
Add a recipient TO to the email using the specified address and the specified personal name. |
Email |
addTo(String email,
String name,
String charset)
Add a recipient TO to the email using the specified address, personal name, and charset encoding for the name. |
void |
buildMimeMessage()
Build the internal MimeMessage to be sent. |
protected javax.mail.internet.MimeMessage |
createMimeMessage(javax.mail.Session aSession)
Factory method to create a customized MimeMessage which can be implemented by a derived class, e.g. |
List |
getBccAddresses()
Get the list of "Bcc" addresses. |
List |
getCcAddresses()
Get the list of "CC" addresses. |
javax.mail.internet.InternetAddress |
getFromAddress()
Gets the sender of the email. |
String |
getHostName()
Gets the host name of the SMTP server, |
javax.mail.Session |
getMailSession()
Initialise a mailsession object |
javax.mail.internet.MimeMessage |
getMimeMessage()
Returns the internal MimeMessage. |
List |
getReplyToAddresses()
Get the list of "Reply-To" addresses. |
Date |
getSentDate()
Gets the sent date for the email. |
String |
getSmtpPort()
Gets the listening port of the SMTP server. |
int |
getSocketConnectionTimeout()
Get the socket connection timeout value in milliseconds. |
int |
getSocketTimeout()
Get the socket I/O timeout value in milliseconds. |
String |
getSslSmtpPort()
Returns the current SSL port used by the SMTP transport. |
String |
getSubject()
Gets the subject of the email. |
List |
getToAddresses()
Get the list of "To" addresses. |
boolean |
isSSL()
Returns whether SSL encryption for the transport is currently enabled. |
boolean |
isTLS()
Gets encryption mode for authentication |
String |
send()
Sends the email. |
String |
sendMimeMessage()
Sends the previously created MimeMessage to the SMTP server. |
void |
setAuthentication(String userName,
String password)
Sets the userName and password if authentication is needed. |
void |
setAuthenticator(javax.mail.Authenticator newAuthenticator)
Sets the Authenticator to be used when authentication
is requested from the mail server. |
Email |
setBcc(Collection aCollection)
Set a list of "BCC" addresses. |
Email |
setBounceAddress(String email)
Set the "bounce address" - the address to which undeliverable messages will be returned. |
Email |
setCc(Collection aCollection)
Set a list of "CC" addresses. |
void |
setCharset(String newCharset)
Set the charset of the message. |
void |
setContent(javax.mail.internet.MimeMultipart aMimeMultipart)
Set the emailBody to a MimeMultiPart |
void |
setContent(Object aObject,
String aContentType)
Set the content & contentType |
void |
setDebug(boolean d)
Setting to true will enable the display of debug information. |
Email |
setFrom(String email)
Set the FROM field of the email to use the specified address. |
Email |
setFrom(String email,
String name)
Set the FROM field of the email to use the specified address and the specified personal name. |
Email |
setFrom(String email,
String name,
String charset)
Set the FROM field of the email to use the specified address, personal name, and charset encoding for the name. |
void |
setHeaders(Map map)
Used to specify the mail headers. |
void |
setHostName(String aHostName)
Set the hostname of the outgoing mail server |
void |
setMailSession(javax.mail.Session aSession)
Supply a mail Session object to use. |
void |
setMailSessionFromJNDI(String jndiName)
Supply a mail Session object from a JNDI directory |
abstract Email |
setMsg(String msg)
Define the content of the mail. |
void |
setPopBeforeSmtp(boolean newPopBeforeSmtp,
String newPopHost,
String newPopUsername,
String newPopPassword)
Set details regarding "pop3 before smtp" authentication. |
Email |
setReplyTo(Collection aCollection)
Set a list of reply to addresses. |
void |
setSentDate(Date date)
Sets the sent date for the email. |
void |
setSmtpPort(int aPortNumber)
Set the port number of the outgoing mail server. |
void |
setSocketConnectionTimeout(int socketConnectionTimeout)
Set the socket connection timeout value in milliseconds. |
void |
setSocketTimeout(int socketTimeout)
Set the socket I/O timeout value in milliseconds. |
void |
setSSL(boolean ssl)
Sets whether SSL encryption should be enabled for the SMTP transport. |
void |
setSslSmtpPort(String sslSmtpPort)
Sets the SSL port to use for the SMTP transport. |
Email |
setSubject(String aSubject)
Set the email subject. |
void |
setTLS(boolean withTLS)
Set or disable the TLS encryption |
Email |
setTo(Collection aCollection)
Set a list of "TO" addresses. |
protected javax.mail.internet.InternetAddress[] |
toInternetAddressArray(List list)
Utility to copy List of known InternetAddress objects into an array. |
void |
updateContentType(String aContentType)
Update the contentType. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String SENDER_EMAIL
public static final String SENDER_NAME
public static final String RECEIVER_EMAIL
public static final String RECEIVER_NAME
public static final String EMAIL_SUBJECT
public static final String EMAIL_BODY
public static final String CONTENT_TYPE
public static final String MAIL_HOST
public static final String MAIL_PORT
public static final String MAIL_SMTP_FROM
public static final String MAIL_SMTP_AUTH
public static final String MAIL_SMTP_USER
public static final String MAIL_SMTP_PASSWORD
public static final String MAIL_TRANSPORT_PROTOCOL
public static final String MAIL_TRANSPORT_TLS
public static final String MAIL_SMTP_SOCKET_FACTORY_FALLBACK
public static final String MAIL_SMTP_SOCKET_FACTORY_CLASS
public static final String MAIL_SMTP_SOCKET_FACTORY_PORT
public static final String MAIL_SMTP_CONNECTIONTIMEOUT
public static final String MAIL_SMTP_TIMEOUT
public static final String SMTP
public static final String TEXT_HTML
public static final String TEXT_PLAIN
public static final String ATTACHMENTS
public static final String FILE_SERVER
public static final String MAIL_DEBUG
public static final String KOI8_R
public static final String ISO_8859_1
public static final String US_ASCII
protected javax.mail.internet.MimeMessage message
protected String charset
protected javax.mail.internet.InternetAddress fromAddress
protected String subject
protected javax.mail.internet.MimeMultipart emailBody
protected Object content
protected String contentType
protected boolean debug
protected Date sentDate
protected javax.mail.Authenticator authenticator
Authenticator
object that will be used
when authentication is requested from the mail server.
protected String hostName
protected String smtpPort
protected String sslSmtpPort
protected List toList
protected List ccList
protected List bccList
protected List replyList
protected String bounceAddress
String
rather than InternetAddress
.
protected Map headers
protected boolean popBeforeSmtp
protected String popHost
protected String popUsername
protected String popPassword
protected boolean tls
protected boolean ssl
protected int socketTimeout
protected int socketConnectionTimeout
Constructor Detail |
---|
public Email()
Method Detail |
---|
public void setDebug(boolean d)
d
- A boolean.public void setAuthentication(String userName, String password)
This method will create a new instance of
DefaultAuthenticator
using the supplied parameters.
userName
- User name for the SMTP serverpassword
- password for the SMTP serverDefaultAuthenticator
,
setAuthenticator(javax.mail.Authenticator)
public void setAuthenticator(javax.mail.Authenticator newAuthenticator)
Authenticator
to be used when authentication
is requested from the mail server.
This method should be used when your outgoing mail server requires authentication. Your mail server must also support RFC2554.
newAuthenticator
- the Authenticator
object.Authenticator
public void setCharset(String newCharset)
newCharset
- A String.
IllegalCharsetNameException
- if the charset name is invalid
UnsupportedCharsetException
- if no support for the named charset
exists in the current JVMpublic void setContent(javax.mail.internet.MimeMultipart aMimeMultipart)
aMimeMultipart
- aMimeMultipartpublic void setContent(Object aObject, String aContentType)
aObject
- aObjectaContentType
- aContentTypepublic void updateContentType(String aContentType)
aContentType
- aContentTypepublic void setHostName(String aHostName)
aHostName
- aHostNamepublic void setTLS(boolean withTLS)
withTLS
- true if TLS needed, false otherwisepublic void setSmtpPort(int aPortNumber)
aPortNumber
- aPortNumberpublic void setMailSession(javax.mail.Session aSession)
aSession
- mail session to be usedpublic void setMailSessionFromJNDI(String jndiName) throws NamingException
jndiName
- name of JNDI ressource (javax.mail.Session type), ressource
if searched in java:comp/env if name dont start with "java:"
IllegalArgumentException
- JNDI name null or empty
NamingException
- ressource can be retrieved from JNDI directorypublic javax.mail.Session getMailSession() throws EmailException
EmailException
- thrown when host name was not set.public Email setFrom(String email) throws EmailException
setCharset()
.
If it is not set, it will be encoded using
the Java platform's default charset (UTF-16) if it contains
non-ASCII characters; otherwise, it is used as is.
email
- A String.
EmailException
- Indicates an invalid email address.public Email setFrom(String email, String name) throws EmailException
setCharset()
.
If it is not set, it will be encoded using
the Java platform's default charset (UTF-16) if it contains
non-ASCII characters; otherwise, it is used as is.
email
- A String.name
- A String.
EmailException
- Indicates an invalid email address.public Email setFrom(String email, String name, String charset) throws EmailException
email
- A String.name
- A String.charset
- The charset to encode the name with.
EmailException
- Indicates an invalid email address or charset.public Email addTo(String email) throws EmailException
setCharset()
.
If it is not set, it will be encoded using
the Java platform's default charset (UTF-16) if it contains
non-ASCII characters; otherwise, it is used as is.
email
- A String.
EmailException
- Indicates an invalid email address.public Email addTo(String email, String name) throws EmailException
setCharset()
.
If it is not set, it will be encoded using
the Java platform's default charset (UTF-16) if it contains
non-ASCII characters; otherwise, it is used as is.
email
- A String.name
- A String.
EmailException
- Indicates an invalid email address.public Email addTo(String email, String name, String charset) throws EmailException
email
- A String.name
- A String.charset
- The charset to encode the name with.
EmailException
- Indicates an invalid email address or charset.public Email setTo(Collection aCollection) throws EmailException
Collection
are expected to be of type
java.mail.internet.InternetAddress
.
aCollection
- collection of InternetAddress
objects.
EmailException
- Indicates an invalid email address.InternetAddress
public Email addCc(String email) throws EmailException
setCharset()
.
If it is not set, it will be encoded using
the Java platform's default charset (UTF-16) if it contains
non-ASCII characters; otherwise, it is used as is.
email
- A String.
EmailException
- Indicates an invalid email address.public Email addCc(String email, String name) throws EmailException
setCharset()
.
If it is not set, it will be encoded using
the Java platform's default charset (UTF-16) if it contains
non-ASCII characters; otherwise, it is used as is.
email
- A String.name
- A String.
EmailException
- Indicates an invalid email address.public Email addCc(String email, String name, String charset) throws EmailException
email
- A String.name
- A String.charset
- The charset to encode the name with.
EmailException
- Indicates an invalid email address or charset.public Email setCc(Collection aCollection) throws EmailException
Collection
are expected to be of type
java.mail.internet.InternetAddress
.
aCollection
- collection of InternetAddress
objects.
EmailException
- Indicates an invalid email address.InternetAddress
public Email addBcc(String email) throws EmailException
setCharset()
.
If it is not set, it will be encoded using
the Java platform's default charset (UTF-16) if it contains
non-ASCII characters; otherwise, it is used as is.
email
- A String.
EmailException
- Indicates an invalid email addresspublic Email addBcc(String email, String name) throws EmailException
setCharset()
.
If it is not set, it will be encoded using
the Java platform's default charset (UTF-16) if it contains
non-ASCII characters; otherwise, it is used as is.
email
- A String.name
- A String.
EmailException
- Indicates an invalid email addresspublic Email addBcc(String email, String name, String charset) throws EmailException
email
- A String.name
- A String.charset
- The charset to encode the name with.
EmailException
- Indicates an invalid email addresspublic Email setBcc(Collection aCollection) throws EmailException
Collection
are expected to be of type
java.mail.internet.InternetAddress
.
aCollection
- collection of InternetAddress
objects
EmailException
- Indicates an invalid email addressInternetAddress
public Email addReplyTo(String email) throws EmailException
setCharset()
.
If it is not set, it will be encoded using
the Java platform's default charset (UTF-16) if it contains
non-ASCII characters; otherwise, it is used as is.
email
- A String.
EmailException
- Indicates an invalid email addresspublic Email addReplyTo(String email, String name) throws EmailException
setCharset()
.
If it is not set, it will be encoded using
the Java platform's default charset (UTF-16) if it contains
non-ASCII characters; otherwise, it is used as is.
email
- A String.name
- A String.
EmailException
- Indicates an invalid email addresspublic Email addReplyTo(String email, String name, String charset) throws EmailException
email
- A String.name
- A String.charset
- The charset to encode the name with.
EmailException
- Indicates an invalid email address or charset.public Email setReplyTo(Collection aCollection) throws EmailException
Collection
are expected to be of type
java.mail.internet.InternetAddress
.
aCollection
- collection of InternetAddress
objects
EmailException
- Indicates an invalid email addressInternetAddress
public void setHeaders(Map map)
map
- A Map.public void addHeader(String name, String value)
name
- A String with the name.value
- A String with the value.public Email setSubject(String aSubject)
aSubject
- A String.
public Email setBounceAddress(String email)
email
- A String.
public abstract Email setMsg(String msg) throws EmailException
msg
- A String.
EmailException
- generic exception.public void buildMimeMessage() throws EmailException
EmailException
- if there was an error.protected javax.mail.internet.MimeMessage createMimeMessage(javax.mail.Session aSession)
aSession
- mail session to be used
public String sendMimeMessage() throws EmailException
EmailException
- the sending failedpublic javax.mail.internet.MimeMessage getMimeMessage()
public String send() throws EmailException
EmailException
- the sending failedpublic void setSentDate(Date date)
date
- Date to use as the sent date on the emailpublic Date getSentDate()
public String getSubject()
public javax.mail.internet.InternetAddress getFromAddress()
public String getHostName()
public String getSmtpPort()
public boolean isTLS()
protected javax.mail.internet.InternetAddress[] toInternetAddressArray(List list)
list
- A List.
public void setPopBeforeSmtp(boolean newPopBeforeSmtp, String newPopHost, String newPopUsername, String newPopPassword)
newPopBeforeSmtp
- Wether or not to log into pop3
server before sending mail.newPopHost
- The pop3 host to use.newPopUsername
- The pop3 username.newPopPassword
- The pop3 password.public boolean isSSL()
public void setSSL(boolean ssl)
ssl
- whether to enable the SSL transportpublic String getSslSmtpPort()
public void setSslSmtpPort(String sslSmtpPort)
sslSmtpPort
- the SSL port to use for the SMTP transportpublic List getToAddresses()
public List getCcAddresses()
public List getBccAddresses()
public List getReplyToAddresses()
public int getSocketConnectionTimeout()
public void setSocketConnectionTimeout(int socketConnectionTimeout)
socketConnectionTimeout
- the connection timeoutpublic int getSocketTimeout()
public void setSocketTimeout(int socketTimeout)
socketTimeout
- the socket I/O timeout
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |