org.codemonkey.simplejavamail
Class Email

java.lang.Object
  extended by org.codemonkey.simplejavamail.Email

public class Email
extends Object

Email message with all necessary data for an effective mailing action, including attachments etc.

Author:
Benny Bottema

Constructor Summary
Email()
          Constructor, creates all internal lists.
 
Method Summary
 void addAttachment(String name, byte[] data, String mimetype)
          Adds an attachment to the email message and generates the necessary DataSource with the given byte data.
 void addAttachment(String name, DataSource filedata)
          Overloaded method which sets an attachment on account of name and DataSource.
 void addEmbeddedImage(String name, byte[] data, String mimetype)
          Adds an embedded image (attachment type) to the email message and generates the necessary DataSource with the given byte data.
 void addEmbeddedImage(String name, DataSource imagedata)
          Overloaded method which sets an embedded image on account of name and DataSource.
 void addHeader(String name, Object value)
          Adds a header to the headers list.
 void addRecipient(String name, String address, javax.mail.Message.RecipientType type)
          Adds a new Recipient to the list on account of name, address and recipient type (eg.
 List<org.codemonkey.simplejavamail.AttachmentResource> getAttachments()
          Bean getter for attachments as unmodifiable list.
 List<org.codemonkey.simplejavamail.AttachmentResource> getEmbeddedImages()
          Bean getter for embeddedImages as unmodifiable list.
 org.codemonkey.simplejavamail.Recipient getFromRecipient()
          Bean getter for fromRecipient.
 Map<String,String> getHeaders()
          Bean getter for headers as unmodifiable map.
 List<org.codemonkey.simplejavamail.Recipient> getRecipients()
          Bean getter for recipients as unmodifiable list.
 org.codemonkey.simplejavamail.Recipient getReplyToRecipient()
          Bean getter for replyToRecipient.
 String getSubject()
          Bean getter for subject.
 String getText()
          Bean getter for text.
 String getTextHTML()
          Bean getter for textHTML.
 void setFromAddress(String name, String fromAddress)
          Sets the sender address.
 void setReplyToAddress(String name, String replyToAddress)
          Sets the reply-to address (optional).
 void setSubject(String subject)
          Bean setters for subject.
 void setText(String text)
          Bean setters for text.
 void setTextHTML(String textHTML)
          Bean setters for textHTML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Email

public Email()
Constructor, creates all internal lists.

Method Detail

setFromAddress

public void setFromAddress(String name,
                           String fromAddress)
Sets the sender address.

Parameters:
name - The sender's name.
fromAddress - The sender's email address.

setReplyToAddress

public void setReplyToAddress(String name,
                              String replyToAddress)
Sets the reply-to address (optional).

Parameters:
name - The replied-to-receiver name.
replyToAddress - The replied-to-receiver email address.

setSubject

public void setSubject(String subject)
Bean setters for subject.


setText

public void setText(String text)
Bean setters for text.


setTextHTML

public void setTextHTML(String textHTML)
Bean setters for textHTML.


addRecipient

public void addRecipient(String name,
                         String address,
                         javax.mail.Message.RecipientType type)
Adds a new Recipient to the list on account of name, address and recipient type (eg. Message.RecipientType.CC).

Parameters:
name - The name of the recipient.
address - The emailadres of the recipient.
type - The type of receiver (eg. Message.RecipientType.CC).
See Also:
recipients, Recipient, Message.RecipientType

addEmbeddedImage

public void addEmbeddedImage(String name,
                             byte[] data,
                             String mimetype)
Adds an embedded image (attachment type) to the email message and generates the necessary DataSource with the given byte data. Then delegates to addEmbeddedImage(String, DataSource). At this point the datasource is actually a ByteArrayDataSource.

Parameters:
name - The name of the image as being referred to from the message content body (eg. '<cid:signature>').
data - The byte data of the image to be embedded.
mimetype - The content type of the given data (eg. "image/gif" or "image/jpeg").
See Also:
ByteArrayDataSource, addEmbeddedImage(String, DataSource)

addEmbeddedImage

public void addEmbeddedImage(String name,
                             DataSource imagedata)
Overloaded method which sets an embedded image on account of name and DataSource.

Parameters:
name - The name of the image as being referred to from the message content body (eg. '<cid:embeddedimage>').
imagedata - The image data.

addHeader

public void addHeader(String name,
                      Object value)
Adds a header to the headers list. The value is stored as a String.

example: email.addHeader("X-Priority", 2)

Parameters:
name - The name of the header.
value - The value of the header, which will be stored using String.valueOf(Object).

addAttachment

public void addAttachment(String name,
                          byte[] data,
                          String mimetype)
Adds an attachment to the email message and generates the necessary DataSource with the given byte data. Then delegates to addAttachment(String, DataSource). At this point the datasource is actually a ByteArrayDataSource.

Parameters:
name - The name of the extension (eg. filename including extension).
data - The byte data of the attachment.
mimetype - The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf").
See Also:
ByteArrayDataSource, addAttachment(String, DataSource)

addAttachment

public void addAttachment(String name,
                          DataSource filedata)
Overloaded method which sets an attachment on account of name and DataSource.

Parameters:
name - The name of the attachment (eg. 'filename.ext').
filedata - The attachment data.

getFromRecipient

public org.codemonkey.simplejavamail.Recipient getFromRecipient()
Bean getter for fromRecipient.


getReplyToRecipient

public org.codemonkey.simplejavamail.Recipient getReplyToRecipient()
Bean getter for replyToRecipient.


getSubject

public String getSubject()
Bean getter for subject.


getText

public String getText()
Bean getter for text.


getTextHTML

public String getTextHTML()
Bean getter for textHTML.


getAttachments

public List<org.codemonkey.simplejavamail.AttachmentResource> getAttachments()
Bean getter for attachments as unmodifiable list.


getEmbeddedImages

public List<org.codemonkey.simplejavamail.AttachmentResource> getEmbeddedImages()
Bean getter for embeddedImages as unmodifiable list.


getRecipients

public List<org.codemonkey.simplejavamail.Recipient> getRecipients()
Bean getter for recipients as unmodifiable list.


getHeaders

public Map<String,String> getHeaders()
Bean getter for headers as unmodifiable map.



Copyright © 2011. All Rights Reserved.