Class MultiPartEmail

  • Direct Known Subclasses:
    HtmlEmail

    public class MultiPartEmail
    extends Email
    A multipart email.

    This class is used to send multi-part internet email like messages with attachments.

    To create a multi-part email, call the default constructor and then you can call setMsg() to set the message and call the different attach() methods.

    Since:
    1.0
    • Constructor Detail

      • MultiPartEmail

        public MultiPartEmail()
    • Method Detail

      • setSubType

        public void setSubType​(java.lang.String aSubType)
        Set the MIME subtype of the email.
        Parameters:
        aSubType - MIME subtype of the email
        Since:
        1.0
      • getSubType

        public java.lang.String getSubType()
        Get the MIME subtype of the email.
        Returns:
        MIME subtype of the email
        Since:
        1.0
      • addPart

        public Email addPart​(java.lang.String partContent,
                             java.lang.String partContentType)
                      throws EmailException
        Add a new part to the email.
        Parameters:
        partContent - The content.
        partContentType - The content type.
        Returns:
        An Email.
        Throws:
        EmailException - see javax.mail.internet.MimeBodyPart for definitions
        Since:
        1.0
      • addPart

        public Email addPart​(MimeMultipart multipart)
                      throws EmailException
        Add a new part to the email.
        Parameters:
        multipart - The MimeMultipart.
        Returns:
        An Email.
        Throws:
        EmailException - see javax.mail.internet.MimeBodyPart for definitions
        Since:
        1.0
      • addPart

        public Email addPart​(MimeMultipart multipart,
                             int index)
                      throws EmailException
        Add a new part to the email.
        Parameters:
        multipart - The part to add.
        index - The index to add at.
        Returns:
        The email.
        Throws:
        EmailException - An error occurred while adding the part.
        Since:
        1.0
      • setMsg

        public Email setMsg​(java.lang.String msg)
                     throws EmailException
        Set the message of the email.
        Specified by:
        setMsg in class Email
        Parameters:
        msg - A String.
        Returns:
        An Email.
        Throws:
        EmailException - see javax.mail.internet.MimeBodyPart for definitions
        Since:
        1.0
      • buildMimeMessage

        public void buildMimeMessage()
                              throws EmailException
        Does the work of actually building the MimeMessage. Please note that a user rarely calls this method directly and only if he/she is interested in the sending the underlying MimeMessage without commons-email.
        Overrides:
        buildMimeMessage in class Email
        Throws:
        EmailException - if there was an error.
        Since:
        1.0
      • attach

        public MultiPartEmail attach​(java.io.File file)
                              throws EmailException
        Attach a file.
        Parameters:
        file - A file attachment
        Returns:
        A MultiPartEmail.
        Throws:
        EmailException - see javax.mail.internet.MimeBodyPart for definitions
        Since:
        1.3
      • attach

        public MultiPartEmail attach​(java.net.URL url,
                                     java.lang.String name,
                                     java.lang.String description)
                              throws EmailException
        Attach a file located by its URL. The disposition of the file is set to mixed.
        Parameters:
        url - The URL of the file (may be any valid URL).
        name - The name field for the attachment.
        description - A description for the attachment.
        Returns:
        A MultiPartEmail.
        Throws:
        EmailException - see javax.mail.internet.MimeBodyPart for definitions
        Since:
        1.0
      • attach

        public MultiPartEmail attach​(java.net.URL url,
                                     java.lang.String name,
                                     java.lang.String description,
                                     java.lang.String disposition)
                              throws EmailException
        Attach a file located by its URL.
        Parameters:
        url - The URL of the file (may be any valid URL).
        name - The name field for the attachment.
        description - A description for the attachment.
        disposition - Either mixed or inline.
        Returns:
        A MultiPartEmail.
        Throws:
        EmailException - see javax.mail.internet.MimeBodyPart for definitions
        Since:
        1.0
      • attach

        public MultiPartEmail attach​(javax.activation.DataSource ds,
                                     java.lang.String name,
                                     java.lang.String description)
                              throws EmailException
        Attach a file specified as a DataSource interface.
        Parameters:
        ds - A DataSource interface for the file.
        name - The name field for the attachment.
        description - A description for the attachment.
        Returns:
        A MultiPartEmail.
        Throws:
        EmailException - see javax.mail.internet.MimeBodyPart for definitions
        Since:
        1.0
      • attach

        public MultiPartEmail attach​(javax.activation.DataSource ds,
                                     java.lang.String name,
                                     java.lang.String description,
                                     java.lang.String disposition)
                              throws EmailException
        Attach a file specified as a DataSource interface.
        Parameters:
        ds - A DataSource interface for the file.
        name - The name field for the attachment.
        description - A description for the attachment.
        disposition - Either mixed or inline.
        Returns:
        A MultiPartEmail.
        Throws:
        EmailException - see javax.mail.internet.MimeBodyPart for definitions
        Since:
        1.0
      • isBoolHasAttachments

        public boolean isBoolHasAttachments()
        Checks whether there are attachments.
        Returns:
        true if there are attachments
        Since:
        1.0
      • setBoolHasAttachments

        public void setBoolHasAttachments​(boolean b)
        Sets whether there are attachments.
        Parameters:
        b - the attachments flag
        Since:
        1.0