org.apache.commons.mail

## Class MultiPartEmail

- java.lang.Object
- - org.apache.commons.mail.Email
  - - org.apache.commons.mail.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

- - ### Field Summary

    - ### Fields inherited from class org.apache.commons.mail.Email

      `ATTACHMENTS, authenticator, bccList, bounceAddress, ccList, charset, content, CONTENT_TYPE, contentType, debug, EMAIL_BODY, EMAIL_SUBJECT, emailBody, FILE_SERVER, fromAddress, headers, hostName, ISO_8859_1, KOI8_R, MAIL_DEBUG, MAIL_HOST, MAIL_PORT, MAIL_SMTP_AUTH, MAIL_SMTP_CONNECTIONTIMEOUT, MAIL_SMTP_FROM, MAIL_SMTP_PASSWORD, MAIL_SMTP_SOCKET_FACTORY_CLASS, MAIL_SMTP_SOCKET_FACTORY_FALLBACK, MAIL_SMTP_SOCKET_FACTORY_PORT, MAIL_SMTP_TIMEOUT, MAIL_SMTP_USER, MAIL_TRANSPORT_PROTOCOL, MAIL_TRANSPORT_TLS, message, popBeforeSmtp, popHost, popPassword, popUsername, RECEIVER_EMAIL, RECEIVER_NAME, replyList, SENDER_EMAIL, SENDER_NAME, sentDate, SMTP, smtpPort, socketConnectionTimeout, socketTimeout, ssl, sslSmtpPort, subject, TEXT_HTML, TEXT_PLAIN, tls, toList, US_ASCII`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MultiPartEmail()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Email` | `addPart(MimeMultipart multipart)` Add a new part to the email.
    `Email` | `addPart(MimeMultipart multipart, int index)` Add a new part to the email.
    `Email` | `addPart(String partContent, String partContentType)` Add a new part to the email.
    `MultiPartEmail` | `attach(DataSource ds, String name, String description)` Attach a file specified as a DataSource interface.
    `MultiPartEmail` | `attach(DataSource ds, String name, String description, String disposition)` Attach a file specified as a DataSource interface.
    `MultiPartEmail` | `attach(EmailAttachment attachment)` Attach an EmailAttachment.
    `MultiPartEmail` | `attach(File file)` Attach a file.
    `MultiPartEmail` | `attach(URL url, String name, String description)` Attach a file located by its URL.
    `MultiPartEmail` | `attach(URL url, String name, String description, String disposition)` Attach a file located by its URL.
    `void` | `buildMimeMessage()` Does the work of actually building the MimeMessage.
    `protected BodyPart` | `createBodyPart()` Creates a body part object.
    `protected MimeMultipart` | `createMimeMultipart()` Creates a mime multipart object.
    `protected MimeMultipart` | `getContainer()` Gets the message container.
    `protected BodyPart` | `getPrimaryBodyPart()` Gets first body part of the message.
    `String` | `getSubType()` Get the MIME subtype of the email.
    `protected void` | `init()` Initialize the multipart email.
    `boolean` | `isBoolHasAttachments()` Checks whether there are attachments.
    `protected boolean` | `isInitialized()` Checks if this object is initialized.
    `void` | `setBoolHasAttachments(boolean b)` Sets whether there are attachments.
    `protected void` | `setInitialized(boolean b)` Sets the initialized status of this object.
    `Email` | `setMsg(String msg)` Set the message of the email.
    `void` | `setSubType(String aSubType)` Set the MIME subtype of the email.

    - ### Methods inherited from class org.apache.commons.mail.Email

      `addBcc, addBcc, addBcc, addBcc, addCc, addCc, addCc, addCc, addHeader, addReplyTo, addReplyTo, addReplyTo, addTo, addTo, addTo, addTo, createMimeMessage, getBccAddresses, getBounceAddress, getCcAddresses, getFromAddress, getHeader, getHeaders, getHostName, getMailSession, getMimeMessage, getReplyToAddresses, getSentDate, getSmtpPort, getSocketConnectionTimeout, getSocketTimeout, getSslSmtpPort, getSubject, getToAddresses, isSendPartial, isSSL, isSSLCheckServerIdentity, isSSLOnConnect, isStartTLSEnabled, isStartTLSRequired, isTLS, send, sendMimeMessage, setAuthentication, setAuthenticator, setBcc, setBounceAddress, setCc, setCharset, setContent, setContent, setDebug, setFrom, setFrom, setFrom, setHeaders, setHostName, setMailSession, setMailSessionFromJNDI, setPopBeforeSmtp, setReplyTo, setSendPartial, setSentDate, setSmtpPort, setSocketConnectionTimeout, setSocketTimeout, setSSL, setSSLCheckServerIdentity, setSSLOnConnect, setSslSmtpPort, setStartTLSEnabled, setStartTLSRequired, setSubject, setTLS, setTo, toInternetAddressArray, updateContentType`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MultiPartEmail

          public MultiPartEmail()

  - ### Method Detail

    - #### setSubType

          public void setSubType(String aSubType)

      Set the MIME subtype of the email.
      Parameters:
        `aSubType` - MIME subtype of the email
      Since:
        1.0

    - #### getSubType

          public String getSubType()

      Get the MIME subtype of the email.
      Returns:
        MIME subtype of the email
      Since:
        1.0

    - #### addPart

          public Email addPart(String partContent,
                               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

    - #### init

          protected void init()

      Initialize the multipart email.
      Since:
        1.0

    - #### setMsg

          public Email setMsg(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(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(EmailAttachment attachment)
                                throws EmailException

      Attach an EmailAttachment.
      Parameters:
        `attachment` - An EmailAttachment.
      Returns:
        A MultiPartEmail.
      Throws:
        `EmailException` - see javax.mail.internet.MimeBodyPart for definitions
      Since:
        1.0

    - #### attach

          public MultiPartEmail attach(URL url,
                                       String name,
                                       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(URL url,
                                       String name,
                                       String description,
                                       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(DataSource ds,
                                       String name,
                                       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(DataSource ds,
                                       String name,
                                       String description,
                                       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

    - #### getPrimaryBodyPart

          protected BodyPart getPrimaryBodyPart()
                                         throws MessagingException

      Gets first body part of the message.
      Returns:
        The primary body part.
      Throws:
        `MessagingException` - An error occurred while getting the primary body part.
      Since:
        1.0

    - #### getContainer

          protected MimeMultipart getContainer()

      Gets the message container.
      Returns:
        The message container.
      Since:
        1.0

    - #### createBodyPart

          protected BodyPart createBodyPart()

      Creates a body part object. Can be overridden if you don't want to create a BodyPart.
      Returns:
        the created body part

    - #### createMimeMultipart

          protected MimeMultipart createMimeMultipart()

      Creates a mime multipart object.
      Returns:
        the created mime part

    - #### 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

    - #### isInitialized

          protected boolean isInitialized()

      Checks if this object is initialized.
      Returns:
        true if initialized

    - #### setInitialized

          protected void setInitialized(boolean b)

      Sets the initialized status of this object.
      Parameters:
        `b` - the initialized status flag

Copyright © 2001–2017 The Apache Software Foundation. All rights reserved.