|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.christopherschultz.mail.MailMessage
public class MailMessage
Provides a nice wrapper around the javamail API for building
an email message to send.
Supports plain text setPlainText(java.lang.String)
and HTML bodies
setHTMLText(java.lang.String)
, attachments attach(java.io.File)
, and embedded files
for use within the HTML body embedHTML(javax.activation.DataSource)
.
Uses UTF-8 as the character set to encode addresses.
Indirectly uses (javamail does this) the content-type specified
by " ;charset=" in calls to setPlainText(String,String)
Field Summary | |
---|---|
static String |
DISPOSITION_ATTACHMENT
A content disposition indicating that an attachment is to be attached as a separate file. |
static String |
DISPOSITION_INLINE
A content disposition indicating that an attachment is to be placed inline. |
Constructor Summary | |
---|---|
MailMessage()
Creates a new MailMessage. |
Method Summary | |
---|---|
MailMessage |
addBcc(javax.mail.Address address)
Adds a blind carbon-copy (BCC) recipient to this message. |
MailMessage |
addBcc(String email)
Adds a blind carbon-copy (BCC) recipient to this message. |
MailMessage |
addBcc(String email,
String name)
Adds a blind carbon-copy (BCC) recipient to this message. |
MailMessage |
addCc(javax.mail.Address address)
Adds a carbon-copy (CC) recipient to this message. |
MailMessage |
addCc(String email)
Adds a carbon-copy (CC) recipient to this message. |
MailMessage |
addCc(String email,
String name)
Adds a carbon-copy (CC) recipient to this message. |
MailMessage |
addHeader(String name,
String value)
Adds an SMTP header to this MailMessage. |
MailMessage |
addReplyTo(javax.mail.Address address)
Adds a reply-to recipient to this message. |
MailMessage |
addReplyTo(String email)
Adds a reply-to recipient to this message. |
MailMessage |
addReplyTo(String email,
String name)
Adds a reply-to recipient to this message. |
MailMessage |
addTo(javax.mail.Address address)
Adds a recipient to this message. |
MailMessage |
addTo(String email)
Adds a recipient to this message. |
MailMessage |
addTo(String email,
String name)
Adds a recipient to this message. |
MailMessage |
attach(javax.activation.DataSource dataSource,
String name)
Attaches the specified DataSource to this message. |
MailMessage |
attach(javax.activation.DataSource dataSource,
String name,
String description)
Attaches the specified DataSource to this message. |
MailMessage |
attach(javax.activation.DataSource dataSource,
String name,
String description,
String disposition)
Attaches the specified DataSource to this message. |
MailMessage |
attach(File file)
Attaches the specified file to this message. |
MailMessage |
attach(String name,
File file)
Attaches the specified file to this message. |
MailMessage |
attach(String name,
String description,
File file)
Attaches the specified file to this message. |
MailMessage |
attach(String name,
String description,
String contentType,
String disposition,
File file)
Attaches the specified file to this message. |
javax.mail.internet.MimeMessage |
buildMimeMessage(javax.mail.Session session)
Builds a MimeMessage object from this MailMessage. |
protected javax.mail.internet.MimeBodyPart |
createHTMLBodyPart(boolean includeMultipartPreamble)
|
String |
embedHTML(javax.activation.DataSource dataSource)
Embeds the specified DataSource in this message's HTML part. |
String |
embedHTML(javax.activation.DataSource dataSource,
String name)
Embeds the specified DataSource in this message's HTML part. |
String |
embedHTML(javax.activation.DataSource dataSource,
String name,
String description)
Embeds the specified DataSource in this message's HTML part. |
String |
embedHTML(javax.activation.DataSource dataSource,
String name,
String description,
String contentId)
Embeds the specified DataSource in this message's HTML part. |
String |
embedHTML(File file)
Embeds the specified File in this message's HTML part. |
String |
embedHTML(String name,
File file)
Embeds the specified File in this message's HTML part. |
String |
embedHTML(String name,
String description,
File file)
Embeds the specified File in this message's HTML part. |
String |
embedHTML(String name,
String description,
String contentType,
File file)
Embeds the specified File in this message's HTML part. |
String |
embedHTML(String name,
String description,
String contentType,
String contentId,
File file)
Embeds the specified File in this message's HTML part. |
protected String |
generateContentId()
|
protected javax.mail.internet.InternetAddress |
makeInternetAddress(String email,
String name,
String charset)
|
void |
send(javax.mail.Session session,
javax.mail.Transport transport)
Sends this message using the specified Session and Transport. |
MailMessage |
setBcc(javax.mail.Address address)
Sets the blind carbon-copy (BCC) recipient for this message. |
MailMessage |
setBcc(String email)
Sets the blind carbon-copy (BCC) recipient for this message. |
MailMessage |
setBcc(String email,
String name)
Sets the blind carbon-copy (BCC) recipient for this message. |
protected void |
setBody(Object messageContainer,
boolean includeMultipartPreamble)
|
MailMessage |
setCc(javax.mail.Address address)
Sets the carbon-copy (CC) recipient of this message. |
MailMessage |
setCc(String email)
Sets the carbon-copy (CC) recipient of this message. |
MailMessage |
setCc(String email,
String name)
Sets the carbon-copy (CC) recipient of this message. |
MailMessage |
setFrom(javax.mail.Address address)
Sets the sender of this message. |
MailMessage |
setFrom(String email)
Sets the sender of this message. |
MailMessage |
setFrom(String email,
String name)
Sets the sender of this message. |
MailMessage |
setHTMLText(String htmlText)
Sets the HTML body of this message. |
MailMessage |
setHTMLText(String htmlText,
String contentType)
Sets the HTML body of this message. |
MailMessage |
setMultipartPreamble(String multipartPreamble)
Sets the multipart preamble for this message. |
MailMessage |
setPlainText(String plainText)
Sets the plain-text body of this message. |
MailMessage |
setPlainText(String plainText,
String contentType)
Sets the plain-text body of this message. |
MailMessage |
setReplyTo(javax.mail.Address address)
Sets the reply-to address for this message. |
MailMessage |
setReplyTo(String email)
Sets the reply-to address for this message. |
MailMessage |
setReplyTo(String email,
String name)
Sets the reply-to address for this message. |
MailMessage |
setSender(javax.mail.Address address)
Sets the sender of this message. |
MailMessage |
setSender(String email)
Sets the sender of this message. |
MailMessage |
setSender(String email,
String name)
Sets the sender of this message. |
protected void |
setSimpleBody(Object messageContainer,
String text,
String contentType)
|
MailMessage |
setSubject(String subject)
Sets the subject of this message. |
MailMessage |
setTo(javax.mail.Address address)
Sets the recipient of this message. |
MailMessage |
setTo(String email)
Sets the recipient of this message. |
MailMessage |
setTo(String email,
String name)
Sets the recipient of this message. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DISPOSITION_ATTACHMENT
public static final String DISPOSITION_INLINE
Constructor Detail |
---|
public MailMessage()
Method Detail |
---|
public MailMessage setMultipartPreamble(String multipartPreamble)
multipartPreamble
- The preamble to use for multipart
messages.
public MailMessage setSender(String email) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the sender.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
setFrom(String)
public MailMessage setSender(String email, String name) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the sender.name
- The name of the sender.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
setFrom(String,String)
public MailMessage setSender(javax.mail.Address address)
address
- The address of the sender.
setFrom(Address)
public MailMessage setFrom(String email) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the sender.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
setSender(String)
public MailMessage setFrom(String email, String name) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the sender.name
- The name of the sender.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
setSender(String,String)
public MailMessage setFrom(javax.mail.Address address)
address
- The address of the sender.
setSender(Address)
public MailMessage setReplyTo(String email) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The reply-to email address for this message.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
addReplyTo(String)
public MailMessage setReplyTo(String email, String name) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The reply-to email address for this message.name
- The name of the reply-to recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
addReplyTo(String,String)
public MailMessage setReplyTo(javax.mail.Address address)
address
- The reply-to address for this message.
addReplyTo(Address)
public MailMessage addReplyTo(String email) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the reply-to recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
setReplyTo(String)
public MailMessage addReplyTo(String email, String name) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the reply-to recipient.name
- The name of the reply-to recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
setReplyTo(String,String)
public MailMessage addReplyTo(javax.mail.Address address)
address
- The address of the reply-to recipient.
setReplyTo(Address)
public MailMessage setTo(String email) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
addTo(String)
public MailMessage setTo(String email, String name) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the recipient.name
- The name of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
addTo(String,String)
public MailMessage setTo(javax.mail.Address address)
address
- The address of the recipient.
addTo(Address)
public MailMessage addTo(String email) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
setTo(String)
public MailMessage addTo(String email, String name) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the recipient.name
- The name of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
setTo(String,String)
public MailMessage addTo(javax.mail.Address address)
address
- The address of the recipient.
setTo(Address)
public MailMessage setCc(String email) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
addCc(String,String)
public MailMessage setCc(String email, String name) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the recipient.name
- The name of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
addCc(String,String)
public MailMessage setCc(javax.mail.Address address)
address
- The address of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.addCc(Address)
public MailMessage addCc(String email) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
setCc(String)
public MailMessage addCc(String email, String name) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the recipient.name
- The name of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
setCc(String,String)
public MailMessage addCc(javax.mail.Address address)
address
- The address of the recipient.
setCc(Address)
public MailMessage setBcc(String email) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
addBcc(String,String)
public MailMessage setBcc(String email, String name) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the recipient.name
- The name of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
addBcc(String,String)
public MailMessage setBcc(javax.mail.Address address)
address
- The address of the recipient.
addBcc(Address)
public MailMessage addBcc(String email) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
setBcc(String)
public MailMessage addBcc(String email, String name) throws UnsupportedEncodingException, javax.mail.internet.AddressException
email
- The email address of the recipient.name
- The name of the recipient.
javax.mail.internet.AddressException
- If there is a problem with the email address.
UnsupportedEncodingException
setBcc(String,String)
public MailMessage addBcc(javax.mail.Address address)
address
- The address of the recipient.
setBcc(Address)
public MailMessage setSubject(String subject)
subject
- The subject of this message.
public MailMessage setPlainText(String plainText)
plainText
- The text to use as the body of this message.
public MailMessage setPlainText(String plainText, String contentType)
plainText
- The text to use as the body of this message.contentType
- The MIME type to use for the message body.
public MailMessage setHTMLText(String htmlText)
htmlText
- The HTML text to use as the body of this message.
public MailMessage setHTMLText(String htmlText, String contentType)
htmlText
- The HTML text to use as the body of this message.contentType
- The MIME type to use for the message body.
public MailMessage attach(File file)
file
- The file to attach.
public MailMessage attach(String name, File file)
name
- The name of the attachment.file
- The file to attach.
public MailMessage attach(String name, String description, File file)
name
- The name of the attachment.description
- The description of the attachment.file
- The file to attach.
public MailMessage attach(String name, String description, String contentType, String disposition, File file)
name
- The name of the attachment.description
- The description of the attachment.contentType
- The MIME type of the attachment.disposition
- Either DISPOSITION_INLINE
or
DISPOSITION_ATTACHMENT
file
- The file to attach.
public MailMessage attach(javax.activation.DataSource dataSource, String name)
dataSource
- The dataSource representing the data to attach.name
- The name of the attachment.
public MailMessage attach(javax.activation.DataSource dataSource, String name, String description)
dataSource
- The dataSource representing the data to attach.name
- The name of the attachment.description
- The description of the attachment.
public MailMessage attach(javax.activation.DataSource dataSource, String name, String description, String disposition)
dataSource
- The dataSource representing the data to attach.name
- The name of the attachment.description
- The description of the attachment.disposition
- Either DISPOSITION_INLINE
or
DISPOSITION_ATTACHMENT
public String embedHTML(javax.activation.DataSource dataSource)
dataSource
- The dataSource representing the data to embed.
public String embedHTML(javax.activation.DataSource dataSource, String name)
dataSource
- The dataSource representing the data to embed.name
- The name of the embedded data.
public String embedHTML(javax.activation.DataSource dataSource, String name, String description)
dataSource
- The dataSource representing the data to embed.name
- The name of the embedded data.description
- The description of the data.
public String embedHTML(javax.activation.DataSource dataSource, String name, String description, String contentId)
dataSource
- The dataSource representing the data to embed.name
- The name of the embedded data.contentId
- The content id to use for the embedded data.
public String embedHTML(File file)
file
- The file to embed.
public String embedHTML(String name, File file)
name
- The name of the embedded data.file
- The file to embed.
public String embedHTML(String name, String description, File file)
name
- The name of the embedded data.description
- The description of the embedded file.file
- The file to embed.
public String embedHTML(String name, String description, String contentType, File file)
name
- The name of the embedded data.description
- The description of the embedded file.contentType
- The MIME type of the embedded file.file
- The file to embed.
public String embedHTML(String name, String description, String contentType, String contentId, File file)
name
- The name of the embedded data.description
- The description of the embedded file.contentType
- The MIME type of the embedded file.contentId
- The content id to use for the embedded data.file
- The file to embed.
public MailMessage addHeader(String name, String value)
name
- The name of the header.value
- The value of the header.
public void send(javax.mail.Session session, javax.mail.Transport transport) throws javax.mail.MessagingException
session
- The JavaMail session to use.transport
- The JavaMail transport to use.
javax.mail.MessagingException
- If there is a problem building or sending
this message.public javax.mail.internet.MimeMessage buildMimeMessage(javax.mail.Session session) throws javax.mail.MessagingException
session
- The JavaMail session in use. null
seems to
work okay, too.
javax.mail.MessagingException
- If there is a problem converting this
MailMessage into a MimeMessage.protected javax.mail.internet.InternetAddress makeInternetAddress(String email, String name, String charset) throws UnsupportedEncodingException, javax.mail.internet.AddressException
UnsupportedEncodingException
javax.mail.internet.AddressException
protected String generateContentId()
protected void setBody(Object messageContainer, boolean includeMultipartPreamble) throws javax.mail.MessagingException
javax.mail.MessagingException
protected javax.mail.internet.MimeBodyPart createHTMLBodyPart(boolean includeMultipartPreamble) throws javax.mail.MessagingException
javax.mail.MessagingException
protected void setSimpleBody(Object messageContainer, String text, String contentType) throws javax.mail.MessagingException
javax.mail.MessagingException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |