Class EMailMessage


  • @PublicAPI(stability=VOLATILE,
               mayInstantiate=true,
               mayExtend=false,
               mayInvoke=true)
    public final class EMailMessage
    extends 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 Detail

      • EMailMessage

        public EMailMessage​(String sender,
                            List<String> recipients,
                            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 String getSender()
        Retrieves the sender for this message.
        Returns:
        The sender for this message.
      • setSender

        public void setSender​(String sender)
        Specifies the sender for this message.
        Parameters:
        sender - The sender for this message.
      • getRecipients

        public List<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​(ArrayList<String> recipients)
        Specifies the set of recipients for this message.
        Parameters:
        recipients - The set of recipients for this message.
      • addRecipient

        public void addRecipient​(String recipient)
        Adds the specified recipient to this message.
        Parameters:
        recipient - The recipient to add to this message.
      • getSubject

        public String getSubject()
        Retrieves the subject for this message.
        Returns:
        The subject for this message.
      • setSubject

        public void setSubject​(String subject)
        Specifies the subject for this message.
        Parameters:
        subject - The subject for this message.
      • getBodyMIMEType

        public String getBodyMIMEType()
        Retrieves the MIME Type for the body of this message.
        Returns:
        The MIME Type for this message.
      • setBodyMIMEType

        public void setBodyMIMEType​(String bodyMIMEType)
        Specifies the MIME Type for the body of this message.
        Parameters:
        bodyMIMEType - The MIME Type for this message.
      • getBody

        public org.forgerock.i18n.LocalizableMessageBuilder 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​(org.forgerock.i18n.LocalizableMessageBuilder body)
        Specifies the body for this message.
        Parameters:
        body - The body for this message.
      • setBody

        public void setBody​(org.forgerock.i18n.LocalizableMessage body)
        Specifies the body for this message.
        Parameters:
        body - The body for this message.
      • appendToBody

        public void appendToBody​(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 List<jakarta.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​(jakarta.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​(String attachmentText)
                           throws jakarta.mail.MessagingException
        Adds an attachment to this mail message with the provided text.
        Parameters:
        attachmentText - The text to include in the attachment.
        Throws:
        jakarta.mail.MessagingException - If there is a problem of some type with the attachment.
      • send

        public void send()
                  throws jakarta.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:
        jakarta.mail.MessagingException - If a problem occurred while attempting to send the message.
      • main

        public static void main​(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.