public abstract class Email
extends java.lang.Object
Description: 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.
Title:首亨软件 - TSS/CRM等
限定符和类型 | 字段和说明 |
---|---|
static java.lang.String |
ATTACHMENTS |
static java.lang.String |
CONTENT_TYPE |
static java.lang.String |
EMAIL_BODY |
static java.lang.String |
EMAIL_SUBJECT |
static java.lang.String |
FILE_SERVER |
static java.lang.String |
ISO_8859_1 |
static java.lang.String |
KOI8_R |
static java.lang.String |
MAIL_DEBUG |
static java.lang.String |
MAIL_HOST |
static java.lang.String |
MAIL_PORT |
static java.lang.String |
MAIL_SMTP_AUTH |
static java.lang.String |
MAIL_SMTP_CONNECTIONTIMEOUT
Socket connection timeout value in milliseconds.
|
static java.lang.String |
MAIL_SMTP_FROM |
static java.lang.String |
MAIL_SMTP_PASSWORD |
static java.lang.String |
MAIL_SMTP_SOCKET_FACTORY_CLASS |
static java.lang.String |
MAIL_SMTP_SOCKET_FACTORY_FALLBACK |
static java.lang.String |
MAIL_SMTP_SOCKET_FACTORY_PORT |
static java.lang.String |
MAIL_SMTP_TIMEOUT
Socket I/O timeout value in milliseconds.
|
static java.lang.String |
MAIL_SMTP_USER |
static java.lang.String |
MAIL_TRANSPORT_PROTOCOL |
static java.lang.String |
MAIL_TRANSPORT_TLS |
static java.lang.String |
RECEIVER_EMAIL |
static java.lang.String |
RECEIVER_NAME |
static java.lang.String |
SENDER_EMAIL |
static java.lang.String |
SENDER_NAME |
static java.lang.String |
SMTP |
static java.lang.String |
TEXT_HTML |
static java.lang.String |
TEXT_PLAIN |
static java.lang.String |
US_ASCII |
构造器和说明 |
---|
Email() |
限定符和类型 | 方法和说明 |
---|---|
Email |
addBcc(java.lang.String email)
Add a blind BCC recipient to the email.
|
Email |
addBcc(java.lang.String email,
java.lang.String name)
Add a blind BCC recipient to the email using the specified address and
the specified personal name.
|
Email |
addBcc(java.lang.String email,
java.lang.String name,
java.lang.String charset)
Add a blind BCC recipient to the email using the specified address,
personal name, and charset encoding for the name.
|
Email |
addCc(java.lang.String email)
Add a recipient CC to the email.
|
Email |
addCc(java.lang.String email,
java.lang.String name)
Add a recipient CC to the email using the specified address and the
specified personal name.
|
Email |
addCc(java.lang.String email,
java.lang.String name,
java.lang.String charset)
Add a recipient CC to the email using the specified address, personal
name, and charset encoding for the name.
|
void |
addHeader(java.lang.String name,
java.lang.String value)
Adds a header ( name, value ) to the headers Map.
|
Email |
addReplyTo(java.lang.String email)
Add a reply to address to the email.
|
Email |
addReplyTo(java.lang.String email,
java.lang.String name)
Add a reply to address to the email using the specified address and
the specified personal name.
|
Email |
addReplyTo(java.lang.String email,
java.lang.String name,
java.lang.String charset)
Add a reply to address to the email using the specified address,
personal name, and charset encoding for the name.
|
Email |
addTo(java.lang.String email)
Add a recipient TO to the email.
|
Email |
addTo(java.lang.String email,
java.lang.String name)
Add a recipient TO to the email using the specified address and the
specified personal name.
|
Email |
addTo(java.lang.String email,
java.lang.String name,
java.lang.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.
|
java.util.List |
getBccAddresses()
Get the list of "Bcc" addresses.
|
java.util.List |
getCcAddresses()
Get the list of "CC" addresses.
|
javax.mail.internet.InternetAddress |
getFromAddress()
Gets the sender of the email.
|
java.lang.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.
|
java.util.List |
getReplyToAddresses()
Get the list of "Reply-To" addresses.
|
java.util.Date |
getSentDate()
Gets the sent date for the email.
|
java.lang.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.
|
java.lang.String |
getSslSmtpPort()
Returns the current SSL port used by the SMTP transport.
|
java.lang.String |
getSubject()
Gets the subject of the email.
|
java.util.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
|
void |
resetToAddress()
重置收件人列表
|
java.lang.String |
send()
Sends the email.
|
java.lang.String |
sendMimeMessage()
Sends the previously created MimeMessage to the SMTP server.
|
void |
setAuthentication(java.lang.String userName,
java.lang.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(java.util.Collection aCollection)
Set a list of "BCC" addresses.
|
Email |
setBounceAddress(java.lang.String email)
Set the "bounce address" - the address to which undeliverable messages
will be returned.
|
Email |
setCc(java.util.Collection aCollection)
Set a list of "CC" addresses.
|
void |
setCharset(java.lang.String newCharset)
Set the charset of the message.
|
void |
setContent(javax.mail.internet.MimeMultipart aMimeMultipart)
Set the emailBody to a MimeMultiPart
|
void |
setContent(java.lang.Object aObject,
java.lang.String aContentType)
Set the content contentType
|
void |
setDebug(boolean d)
Setting to true will enable the display of debug information.
|
Email |
setFrom(java.lang.String email)
Set the FROM field of the email to use the specified address.
|
Email |
setFrom(java.lang.String email,
java.lang.String name)
Set the FROM field of the email to use the specified address and the
specified personal name.
|
Email |
setFrom(java.lang.String email,
java.lang.String name,
java.lang.String charset)
Set the FROM field of the email to use the specified address, personal
name, and charset encoding for the name.
|
void |
setHeaders(java.util.Map map)
Used to specify the mail headers.
|
void |
setHostName(java.lang.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(java.lang.String jndiName)
Supply a mail Session object from a JNDI directory
|
abstract Email |
setMsg(java.lang.String msg)
Define the content of the mail.
|
void |
setPopBeforeSmtp(boolean newPopBeforeSmtp,
java.lang.String newPopHost,
java.lang.String newPopUsername,
java.lang.String newPopPassword)
Set details regarding "pop3 before smtp" authentication.
|
Email |
setReplyTo(java.util.Collection aCollection)
Set a list of reply to addresses.
|
void |
setSentDate(java.util.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(java.lang.String sslSmtpPort)
Sets the SSL port to use for the SMTP transport.
|
Email |
setSubject(java.lang.String aSubject)
Set the email subject.
|
void |
setTLS(boolean withTLS)
Set or disable the TLS encryption
|
Email |
setTo(java.util.Collection aCollection)
Set a list of "TO" addresses.
|
void |
updateContentType(java.lang.String aContentType)
Update the contentType.
|
public static final java.lang.String SENDER_EMAIL
public static final java.lang.String SENDER_NAME
public static final java.lang.String RECEIVER_EMAIL
public static final java.lang.String RECEIVER_NAME
public static final java.lang.String EMAIL_SUBJECT
public static final java.lang.String EMAIL_BODY
public static final java.lang.String CONTENT_TYPE
public static final java.lang.String MAIL_HOST
public static final java.lang.String MAIL_PORT
public static final java.lang.String MAIL_SMTP_FROM
public static final java.lang.String MAIL_SMTP_AUTH
public static final java.lang.String MAIL_SMTP_USER
public static final java.lang.String MAIL_SMTP_PASSWORD
public static final java.lang.String MAIL_TRANSPORT_PROTOCOL
public static final java.lang.String MAIL_TRANSPORT_TLS
public static final java.lang.String MAIL_SMTP_SOCKET_FACTORY_FALLBACK
public static final java.lang.String MAIL_SMTP_SOCKET_FACTORY_CLASS
public static final java.lang.String MAIL_SMTP_SOCKET_FACTORY_PORT
public static final java.lang.String MAIL_SMTP_CONNECTIONTIMEOUT
public static final java.lang.String MAIL_SMTP_TIMEOUT
public static final java.lang.String SMTP
public static final java.lang.String TEXT_HTML
public static final java.lang.String TEXT_PLAIN
public static final java.lang.String ATTACHMENTS
public static final java.lang.String FILE_SERVER
public static final java.lang.String MAIL_DEBUG
public static final java.lang.String KOI8_R
public static final java.lang.String ISO_8859_1
public static final java.lang.String US_ASCII
public void setDebug(boolean d)
d
- A boolean.public void setAuthentication(java.lang.String userName, java.lang.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(java.lang.String newCharset)
newCharset
- A String.java.nio.charset.IllegalCharsetNameException
- if the charset name is invalidjava.nio.charset.UnsupportedCharsetException
- if no support for the named charset
exists in the current JVMpublic void setContent(javax.mail.internet.MimeMultipart aMimeMultipart)
aMimeMultipart
- aMimeMultipartpublic void setContent(java.lang.Object aObject, java.lang.String aContentType)
aObject
- aObjectaContentType
- aContentTypepublic void updateContentType(java.lang.String aContentType)
aContentType
- aContentTypepublic void setHostName(java.lang.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(java.lang.String jndiName) throws javax.naming.NamingException
jndiName
- name of JNDI ressource (javax.mail.Session type), ressource
if searched in java:comp/env if name dont start with "java:"java.lang.IllegalArgumentException
- JNDI name null or emptyjavax.naming.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(java.lang.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(java.lang.String email, java.lang.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(java.lang.String email, java.lang.String name, java.lang.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(java.lang.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(java.lang.String email, java.lang.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(java.lang.String email, java.lang.String name, java.lang.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(java.util.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(java.lang.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(java.lang.String email, java.lang.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(java.lang.String email, java.lang.String name, java.lang.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(java.util.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(java.lang.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(java.lang.String email, java.lang.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(java.lang.String email, java.lang.String name, java.lang.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(java.util.Collection aCollection) throws EmailException
Collection
are expected to be of type
java.mail.internet.InternetAddress
.aCollection
- collection of InternetAddress
objectsEmailException
- Indicates an invalid email addressInternetAddress
public Email addReplyTo(java.lang.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(java.lang.String email, java.lang.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(java.lang.String email, java.lang.String name, java.lang.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(java.util.Collection aCollection) throws EmailException
Collection
are expected to be of type
java.mail.internet.InternetAddress
.aCollection
- collection of InternetAddress
objectsEmailException
- Indicates an invalid email addressInternetAddress
public void setHeaders(java.util.Map map)
map
- A Map.public void addHeader(java.lang.String name, java.lang.String value)
name
- A String with the name.value
- A String with the value.public Email setSubject(java.lang.String aSubject)
aSubject
- A String.public Email setBounceAddress(java.lang.String email)
email
- A String.public abstract Email setMsg(java.lang.String msg) throws EmailException
msg
- A String.EmailException
- generic exception.public void buildMimeMessage() throws EmailException
EmailException
- if there was an error.public java.lang.String sendMimeMessage() throws EmailException
EmailException
- the sending failedpublic javax.mail.internet.MimeMessage getMimeMessage()
public java.lang.String send() throws EmailException
EmailException
- the sending failedpublic void setSentDate(java.util.Date date)
date
- Date to use as the sent date on the emailpublic java.util.Date getSentDate()
public java.lang.String getSubject()
public javax.mail.internet.InternetAddress getFromAddress()
public java.lang.String getHostName()
public java.lang.String getSmtpPort()
public boolean isTLS()
public void setPopBeforeSmtp(boolean newPopBeforeSmtp, java.lang.String newPopHost, java.lang.String newPopUsername, java.lang.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 java.lang.String getSslSmtpPort()
public void setSslSmtpPort(java.lang.String sslSmtpPort)
sslSmtpPort
- the SSL port to use for the SMTP transportpublic java.util.List getToAddresses()
public void resetToAddress()
public java.util.List getCcAddresses()
public java.util.List getBccAddresses()
public java.util.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