|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.mail.Mail
Represents a email message with optional attachments. This class is a wrapper for the JavaMail API that makes it easier for application developers to create and send email. For simple plain text message, there is a static convenience method that does not require the construction of an explicit Mail object:
Mail.send(to, from, subject, body)
For more complex messages, the API provides methods to set all standard mail headers, attach other pieces of content, and finally invoke the transport process to deliver the message.
Field Summary | |
static String |
ATTACHMENT
Disposition of "attachment" |
static String |
INLINE
Disposition of "inline" |
Fields inherited from interface com.arsdigita.util.MessageType |
TEXT_HTML, TEXT_PLAIN, TEXT_PREFORMATTED, TEXT_SMART |
Constructor Summary | |
Mail()
Default constructor. |
|
Mail(String to,
String from,
String subject)
Constructor used to specify to, from, and subject. |
|
Mail(String to,
String from,
String subject,
String body)
Constructor used to specify to, from, subject, and body. |
|
Mail(String to,
String from,
String subject,
String body,
String enc)
Constructor used to specify to, from, subject, body, and encoding. |
Method Summary | |
void |
addHeader(String name,
String value)
Adds a header (name, value) pair. |
void |
attach(byte[] data,
String type,
String name)
Attaches a byte array to a message. |
void |
attach(byte[] data,
String type,
String name,
String description,
String disposition)
Attaches a byte array to a message. |
protected void |
attach(ByteArrayDataSource dataSource,
String description,
String disposition)
Attaches the content from a ByteArrayDataSource to a message. |
void |
attach(ByteArrayInputStream is,
String type,
String name)
Attaches the content from a ByteArrayInputStream to a message. |
void |
attach(ByteArrayInputStream is,
String type,
String name,
String description,
String disposition)
Attaches the content from a ByteArrayInputStream to a message. |
void |
attach(javax.activation.DataHandler dh)
Attaches content to a message by supplying a DataHandler. |
void |
attach(javax.activation.DataHandler dh,
String description,
String disposition)
Attaches content to a message by supplying a DataHandler. |
void |
attach(File path,
String name,
String description)
Adds an attachment with a specified name and description to a message by fetching its content from a local file. |
void |
attach(File path,
String name,
String description,
String disposition)
Adds an attachment with a specified name, description and disposition to a message by fetching its content from a local file. |
void |
attach(String data,
String type,
String name)
Attaches a String to a message. |
void |
attach(String data,
String type,
String name,
String description,
String disposition)
Attaches a String to a message. |
void |
attach(URL url,
String name,
String description)
Adds an attachment with a specified name and description to a message by fetching its content from a URL. |
void |
attach(URL url,
String name,
String description,
String disposition)
Adds an attachment with a specified name, description and disposition to a message by fetching its content from a URL. |
String |
getEncoding()
Returns the character encoding that is being used. |
static String |
getSmtpServer()
Returns the SMTP mail host for debugging and account information. |
void |
send()
Sends the message. |
static void |
send(String to,
String from,
String subject,
String body)
A convenience method to send a simple plain-text message. |
void |
setBcc(String bcc)
Sets the email address that is being blind carbon-copied. |
void |
setBody(String body)
Sets the body of the email to a simple plain text message. |
void |
setBody(String body,
String alt)
Sets the body of the email to an HTML encoded message with a plain text alternative. |
void |
setCc(String cc)
Sets the email address that is being carbon-copied. |
void |
setEncoding(String enc)
Sets the character encoding. |
void |
setFrom(String from)
Sets the email address that the message is being sent from. |
void |
setHeaders(String headers)
Sets the mail's MIME headers. |
void |
setMessageID(String messageID)
Sets the Message ID |
void |
setReplyTo(String replyTo)
Sets the replyTo address. |
void |
setSubject(String subject)
Sets the subject of the message. |
void |
setTo(String to)
Sets the email address that the message is being sent to. |
void |
writeTo(OutputStream os)
Writes the content of the message to the given output stream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String INLINE
public static final String ATTACHMENT
Constructor Detail |
public Mail()
public Mail(String to, String from, String subject)
to
- one or more of addresses to send the message tofrom
- the address the message is being sent fromsubject
- the subject for the messagepublic Mail(String to, String from, String subject, String body)
to
- one or more of addresses to send the message tofrom
- the address the message is being sent fromsubject
- the subject for the messagebody
- the plain text body of the messagepublic Mail(String to, String from, String subject, String body, String enc)
to
- one or more of addresses to send the message tofrom
- the address the message is being sent fromsubject
- the subject for the messagebody
- is plain text body of the messageenc
- the encoding of the bodyMethod Detail |
public static void send(String to, String from, String subject, String body) throws javax.mail.MessagingException, javax.mail.SendFailedException
to
- one or more of addresses to send the message tofrom
- the address the message is being sent fromsubject
- the subject for the messagebody
- the plain text body of the message
javax.mail.MessagingException
javax.mail.SendFailedException
public void send() throws javax.mail.MessagingException, javax.mail.SendFailedException
javax.mail.MessagingException
javax.mail.SendFailedException
public void setTo(String to)
to
- one or more addresses to send the message topublic void setFrom(String from)
from
- the address the message is sent frompublic void setSubject(String subject)
subject
- the subject of the messagepublic void setReplyTo(String replyTo)
replyTo
- the address to use for repliespublic void setMessageID(String messageID)
messageID
- unique identifier for each email.public void setHeaders(String headers)
headers
- a String containing MIME headerspublic void addHeader(String name, String value)
name
- the header element namevalue
- the header element valuepublic void setCc(String cc)
cc
- the email address for a carbon copypublic void setBcc(String bcc)
bcc
- the email address for a blind carbon copypublic void setBody(String body)
body
- the body of the message in plain textpublic void setBody(String body, String alt)
body
- the body of the message in HTMLalt
- the alternate message body in plain textpublic void setEncoding(String enc)
enc
- the requested encodingpublic String getEncoding()
public void attach(URL url, String name, String description) throws javax.mail.MessagingException
url
- the URL to retreieve the content fromname
- the name of the attachmentdescription
- a description of the attachment
javax.mail.MessagingException
public void attach(URL url, String name, String description, String disposition) throws javax.mail.MessagingException
url
- the URL to retreieve the content fromname
- the name of the attachmentdescription
- a description of the attachmentdisposition
- Mail.ATTACHMENT or Mail.INLINE
javax.mail.MessagingException
public void attach(File path, String name, String description) throws javax.mail.MessagingException
path
- the file path to retreieve the content fromname
- the name of the attachmentdescription
- a description of the attachment
javax.mail.MessagingException
public void attach(File path, String name, String description, String disposition) throws javax.mail.MessagingException
path
- the file path to retreieve the content fromname
- the name of the attachmentdescription
- a description of the attachmentdisposition
- Mail.ATTACHMENT or Mail.INLINE
javax.mail.MessagingException
public void attach(byte[] data, String type, String name) throws javax.mail.MessagingException
data
- the content of the attachmenttype
- the MIME type of the attachmentname
- the name of the attachment
javax.mail.MessagingException
public void attach(byte[] data, String type, String name, String description, String disposition) throws javax.mail.MessagingException
data
- the content of the attachmenttype
- the MIME type of the attachmentname
- the name of the attachmentdescription
- a description of the attachmentdisposition
- Mail.ATTACHMENT or Mail.INLINE
javax.mail.MessagingException
public void attach(String data, String type, String name) throws javax.mail.MessagingException
data
- the content of the attachmenttype
- the MIME type of the attachmentname
- the name of the attachment
javax.mail.MessagingException
public void attach(String data, String type, String name, String description, String disposition) throws javax.mail.MessagingException
data
- the content of the attachmenttype
- the MIME type of the attachmentname
- the name of the attachmentdescription
- a description of the attachmentdisposition
- Mail.ATTACHMENT or Mail.INLINE
javax.mail.MessagingException
public void attach(ByteArrayInputStream is, String type, String name) throws javax.mail.MessagingException
is
- the input stream to read from.type
- the MIME type of the attachmentname
- the name of the attachment
javax.mail.MessagingException
public void attach(ByteArrayInputStream is, String type, String name, String description, String disposition) throws javax.mail.MessagingException
is
- the input stream to read from.type
- the MIME type of the attachmentname
- the name of the attachmentdescription
- a description of the attachmentdisposition
- Mail.ATTACHMENT or Mail.INLINE
javax.mail.MessagingException
protected void attach(ByteArrayDataSource dataSource, String description, String disposition) throws javax.mail.MessagingException
dataSource
- the data source to read fromdescription
- a description of the attachmentdisposition
- Mail.ATTACHMENT or Mail.INLINE
javax.mail.MessagingException
public void attach(javax.activation.DataHandler dh) throws javax.mail.MessagingException
dh
- a DataHandler for some piece of content.
javax.mail.MessagingException
public void attach(javax.activation.DataHandler dh, String description, String disposition) throws javax.mail.MessagingException
dh
- the data source to read fromdescription
- a description of the attachmentdisposition
- Mail.ATTACHMENT or Mail.INLINE
javax.mail.MessagingException
public static String getSmtpServer()
public void writeTo(OutputStream os) throws javax.mail.MessagingException
os
- the output stream to write the message to
javax.mail.MessagingException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |