public class HtmlEmail extends MultiPartEmail
Description: An HTML multipart email.
Title:首亨软件 - TSS/CRM等
限定符和类型 | 字段和说明 |
---|---|
static int |
CID_LENGTH
Definition of the length of generated CID's
|
ATTACHMENTS, CONTENT_TYPE, EMAIL_BODY, EMAIL_SUBJECT, FILE_SERVER, ISO_8859_1, KOI8_R, MAIL_DEBUG, MAIL_HOST, MAIL_PORT, MAIL_SMTP_AUTH, MAIL_SMTP_CONNECTIONTIMEOUT, MAIL_SMTP_FROM, MAIL_SMTP_PASSWORD, MAIL_SMTP_SOCKET_FACTORY_CLASS, MAIL_SMTP_SOCKET_FACTORY_FALLBACK, MAIL_SMTP_SOCKET_FACTORY_PORT, MAIL_SMTP_TIMEOUT, MAIL_SMTP_USER, MAIL_TRANSPORT_PROTOCOL, MAIL_TRANSPORT_TLS, RECEIVER_EMAIL, RECEIVER_NAME, SENDER_EMAIL, SENDER_NAME, SMTP, TEXT_HTML, TEXT_PLAIN, US_ASCII
构造器和说明 |
---|
HtmlEmail() |
限定符和类型 | 方法和说明 |
---|---|
void |
buildMimeMessage()
Does the work of actually building the email.
|
java.lang.String |
embed(javax.activation.DataSource dataSource,
java.lang.String name)
Embeds the specified
DataSource in the HTML using a
randomly generated Content-ID. |
java.lang.String |
embed(javax.activation.DataSource dataSource,
java.lang.String name,
java.lang.String cid)
Embeds the specified
DataSource in the HTML using the
specified Content-ID. |
java.lang.String |
embed(java.io.File file)
Embeds a file in the HTML.
|
java.lang.String |
embed(java.io.File file,
java.lang.String cid)
Embeds a file in the HTML.
|
java.lang.String |
embed(java.lang.String urlString,
java.lang.String name)
Attempts to parse the specified
String as a URL that will
then be embedded in the message. |
java.lang.String |
embed(java.net.URL url,
java.lang.String name)
Embeds an URL in the HTML.
|
HtmlEmail |
setHtmlMsg(java.lang.String aHtml)
Set the HTML content.
|
Email |
setMsg(java.lang.String msg)
Set the message.
|
HtmlEmail |
setTextMsg(java.lang.String aText)
Set the text content.
|
addPart, addPart, addPart, attach, attach, attach, attach, attach, getSubType, isBoolHasAttachments, setBoolHasAttachments, setSubType
addBcc, addBcc, addBcc, addCc, addCc, addCc, addHeader, addReplyTo, addReplyTo, addReplyTo, addTo, addTo, addTo, getBccAddresses, getCcAddresses, getFromAddress, getHostName, getMailSession, getMimeMessage, getReplyToAddresses, getSentDate, getSmtpPort, getSocketConnectionTimeout, getSocketTimeout, getSslSmtpPort, getSubject, getToAddresses, isSSL, isTLS, resetToAddress, send, sendMimeMessage, setAuthentication, setAuthenticator, setBcc, setBounceAddress, setCc, setCharset, setContent, setContent, setDebug, setFrom, setFrom, setFrom, setHeaders, setHostName, setMailSession, setMailSessionFromJNDI, setPopBeforeSmtp, setReplyTo, setSentDate, setSmtpPort, setSocketConnectionTimeout, setSocketTimeout, setSSL, setSslSmtpPort, setSubject, setTLS, setTo, updateContentType
public static final int CID_LENGTH
public HtmlEmail setTextMsg(java.lang.String aText) throws EmailException
aText
- A String.EmailException
- see javax.mail.internet.MimeBodyPart
for definitionspublic HtmlEmail setHtmlMsg(java.lang.String aHtml) throws EmailException
aHtml
- A String.EmailException
- see javax.mail.internet.MimeBodyPart
for definitionspublic Email setMsg(java.lang.String msg) throws EmailException
This method overrides MultiPartEmail.setMsg(String)
in
order to send an HTML message instead of a plain text message in
the mail body. The message is formatted in HTML for the HTML
part of the message; it is left as is in the alternate text
part.
setMsg
在类中 MultiPartEmail
msg
- the message text to useHtmlEmail
EmailException
- if msg is null or empty;
see javax.mail.internet.MimeBodyPart for definitionspublic java.lang.String embed(java.lang.String urlString, java.lang.String name) throws EmailException
String
as a URL that will
then be embedded in the message.urlString
- String representation of the URL.name
- The name that will be set in the filename header field.EmailException
- when URL supplied is invalid or if is null
or empty; also see MimeBodyPart
for definitionsembed(URL, String)
public java.lang.String embed(java.net.URL url, java.lang.String name) throws EmailException
This method embeds a file located by an URL into
the mail body. It allows, for instance, to add inline images
to the email. Inline files may be referenced with a
cid:xxxxxx
URL, where xxxxxx is the Content-ID
returned by the embed function. It is an error to bind the same name
to more than one URL; if the same URL is embedded multiple times, the
same Content-ID is guaranteed to be returned.
While functionally the same as passing URLDataSource
to
embed(DataSource, String, String)
, this method attempts
to validate the URL before embedding it in the message and will throw
EmailException
if the validation fails. In this case, the
HtmlEmail
object will not be changed.
NOTE: Clients should take care to ensure that different URLs are bound to
different names. This implementation tries to detect this and throw
EmailException
. However, it is not guaranteed to catch
all cases, especially when the URL refers to a remote HTTP host that
may be part of a virtual host cluster.
url
- The URL of the file.name
- The name that will be set in the filename header
field.EmailException
- when URL supplied is invalid or if is null
or empty; also see MimeBodyPart
for definitionspublic java.lang.String embed(java.io.File file) throws EmailException
embed(File, String)
.file
- The File
object to embedEmailException
- when the supplied File
cannot be
used; also see MimeBodyPart
for definitionsembed(File, String)
public java.lang.String embed(java.io.File file, java.lang.String cid) throws EmailException
This method embeds a file located by an URL into
the mail body. It allows, for instance, to add inline images
to the email. Inline files may be referenced with a
cid:xxxxxx
URL, where xxxxxx is the Content-ID
returned by the embed function. Files are bound to their names, which is
the value returned by File.getName()
. If the same file
is embedded multiple times, the same CID is guaranteed to be returned.
While functionally the same as passing FileDataSource
to
embed(DataSource, String, String)
, this method attempts
to validate the file before embedding it in the message and will throw
EmailException
if the validation fails. In this case, the
HtmlEmail
object will not be changed.
file
- The File
to embedcid
- the Content-ID to use for the embedded File
EmailException
- when the supplied File
cannot be used
or if the file has already been embedded;
also see MimeBodyPart
for definitionspublic java.lang.String embed(javax.activation.DataSource dataSource, java.lang.String name) throws EmailException
DataSource
in the HTML using a
randomly generated Content-ID. Returns the generated Content-ID string.dataSource
- the DataSource
to embedname
- the name that will be set in the filename header fieldDataSource
EmailException
- if the embedding fails or if name
is
null or emptyembed(DataSource, String, String)
public java.lang.String embed(javax.activation.DataSource dataSource, java.lang.String name, java.lang.String cid) throws EmailException
DataSource
in the HTML using the
specified Content-ID. Returns the specified Content-ID string.dataSource
- the DataSource
to embedname
- the name that will be set in the filename header fieldcid
- the Content-ID to use for this DataSource
DataSource
EmailException
- if the embedding fails or if name
is
null or emptypublic void buildMimeMessage() throws EmailException
buildMimeMessage
在类中 MultiPartEmail
EmailException
- if there was an error.