org.opends.server.util
Class EMailMessage

java.lang.Object
  extended by org.opends.server.util.EMailMessage

@PublicAPI(stability=VOLATILE,
           mayInstantiate=true,
           mayExtend=false,
           mayInvoke=true)
public final class EMailMessage
extends java.lang.Object

This class defines an e-mail message that may be sent to one or more recipients via SMTP. This is a wrapper around JavaMail to make this process more convenient and fit better into the Directory Server framework.


Constructor Summary
EMailMessage(java.lang.String sender, java.util.List<java.lang.String> recipients, java.lang.String subject)
          Creates a new e-mail message with the provided information.
EMailMessage(java.lang.String sender, java.lang.String recipient, java.lang.String subject)
          Creates a new e-mail message with the provided information.
 
Method Summary
 void addAttachment(java.io.File attachmentFile)
          Adds the provided attachment to this mail message.
 void addAttachment(javax.mail.internet.MimeBodyPart attachment)
          Adds the provided attachment to this mail message.
 void addAttachment(java.lang.String attachmentText)
          Adds an attachment to this mail message with the provided text.
 void addRecipient(java.lang.String recipient)
          Adds the specified recipient to this message.
 void appendToBody(java.lang.String text)
          Appends the provided text to the body of this message.
 java.util.LinkedList<javax.mail.internet.MimeBodyPart> getAttachments()
          Retrieves the set of attachments for this message.
 MessageBuilder getBody()
          Retrieves the body for this message.
 java.util.List<java.lang.String> getRecipients()
          Retrieves the set of recipients for this message.
 java.lang.String getSender()
          Retrieves the sender for this message.
 java.lang.String getSubject()
          Retrieves the subject for this message.
static void main(java.lang.String[] args)
          Provide a command-line mechanism for sending an e-mail message via SMTP.
 void send()
          Attempts to send this message to the intended recipient(s).
 void send(java.util.List<java.util.Properties> mailServerPropertySets)
          Attempts to send this message to the intended recipient(s).
 void setBody(Message body)
          Specifies the body for this message.
 void setBody(MessageBuilder body)
          Specifies the body for this message.
 void setRecipients(java.util.ArrayList<java.lang.String> recipients)
          Specifies the set of recipients for this message.
 void setSender(java.lang.String sender)
          Specifies the sender for this message.
 void setSubject(java.lang.String subject)
          Specifies the subject for this message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EMailMessage

public EMailMessage(java.lang.String sender,
                    java.lang.String recipient,
                    java.lang.String subject)
Creates a new e-mail message with the provided information.

Parameters:
sender - The address of the sender for the message.
recipient - The address of the recipient for the message.
subject - The subject to use for the message.

EMailMessage

public EMailMessage(java.lang.String sender,
                    java.util.List<java.lang.String> recipients,
                    java.lang.String subject)
Creates a new e-mail message with the provided information.

Parameters:
sender - The address of the sender for the message.
recipients - The addresses of the recipients for the message.
subject - The subject to use for the message.
Method Detail

getSender

public java.lang.String getSender()
Retrieves the sender for this message.

Returns:
The sender for this message.

setSender

public void setSender(java.lang.String sender)
Specifies the sender for this message.

Parameters:
sender - The sender for this message.

getRecipients

public java.util.List<java.lang.String> getRecipients()
Retrieves the set of recipients for this message. This list may be directly manipulated by the caller.

Returns:
The set of recipients for this message.

setRecipients

public void setRecipients(java.util.ArrayList<java.lang.String> recipients)
Specifies the set of recipients for this message.

Parameters:
recipients - The set of recipients for this message.

addRecipient

public void addRecipient(java.lang.String recipient)
Adds the specified recipient to this message.

Parameters:
recipient - The recipient to add to this message.

getSubject

public java.lang.String getSubject()
Retrieves the subject for this message.

Returns:
The subject for this message.

setSubject

public void setSubject(java.lang.String subject)
Specifies the subject for this message.

Parameters:
subject - The subject for this message.

getBody

public MessageBuilder getBody()
Retrieves the body for this message. It may be directly manipulated by the caller.

Returns:
The body for this message.

setBody

public void setBody(MessageBuilder body)
Specifies the body for this message.

Parameters:
body - The body for this message.

setBody

public void setBody(Message body)
Specifies the body for this message.

Parameters:
body - The body for this message.

appendToBody

public void appendToBody(java.lang.String text)
Appends the provided text to the body of this message.

Parameters:
text - The text to append to the body of the message.

getAttachments

public java.util.LinkedList<javax.mail.internet.MimeBodyPart> getAttachments()
Retrieves the set of attachments for this message. This list may be directly modified by the caller if desired.

Returns:
The set of attachments for this message.

addAttachment

public void addAttachment(javax.mail.internet.MimeBodyPart attachment)
Adds the provided attachment to this mail message.

Parameters:
attachment - The attachment to add to this mail message.

addAttachment

public void addAttachment(java.lang.String attachmentText)
                   throws javax.mail.MessagingException
Adds an attachment to this mail message with the provided text.

Parameters:
attachmentText - The text to include in the attachment.
Throws:
javax.mail.MessagingException - If there is a problem of some type with the attachment.

addAttachment

public void addAttachment(java.io.File attachmentFile)
                   throws javax.mail.MessagingException
Adds the provided attachment to this mail message.

Parameters:
attachmentFile - The file containing the attachment data.
Throws:
javax.mail.MessagingException - If there is a problem of some type with the attachment.

send

public void send()
          throws javax.mail.MessagingException
Attempts to send this message to the intended recipient(s). This will use the mail server(s) defined in the Directory Server mail handler configuration. If multiple servers are specified and the first is unavailable, then the other server(s) will be tried before returning a failure to the caller.

Throws:
javax.mail.MessagingException - If a problem occurred while attempting to send the message.

send

public void send(java.util.List<java.util.Properties> mailServerPropertySets)
          throws javax.mail.MessagingException
Attempts to send this message to the intended recipient(s). If multiple servers are specified and the first is unavailable, then the other server(s) will be tried before returning a failure to the caller.

Parameters:
mailServerPropertySets - A list of property sets providing information about the mail servers to use when sending the message.
Throws:
javax.mail.MessagingException - If a problem occurred while attempting to send the message.

main

public static void main(java.lang.String[] args)
Provide a command-line mechanism for sending an e-mail message via SMTP.

Parameters:
args - The command-line arguments provided to this program.