org.apache.commons.mail

## Class ImageHtmlEmail

- java.lang.Object
- - org.apache.commons.mail.Email
  - - org.apache.commons.mail.MultiPartEmail
    - - org.apache.commons.mail.HtmlEmail
      - - org.apache.commons.mail.ImageHtmlEmail

-     public class ImageHtmlEmail
      extends HtmlEmail

  Small wrapper class on top of HtmlEmail which encapsulates the required logic to retrieve images that are contained in "<img src=../>" elements in the HTML code. This is done by replacing all img-src-elements with "cid:"-entries and embedding images in the email.

  For local files the class tries to either load them via an absolute path or - if available - use a relative path starting from a base directory. For files that are not found locally, the implementation tries to download the element and link it in.

  The image loading is done by an instance of `DataSourceResolver` which has to be provided by the caller.

  Since:
    1.3

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `REGEX_IMG_SRC` Regexp for extracting `<img>` tags
    `static String` | `REGEX_SCRIPT_SRC` regexp for extracting `<script>` tags

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

      `CID_LENGTH, html, inlineEmbeds, inlineImages, text`

    - ### 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
    `ImageHtmlEmail()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `buildMimeMessage()` Does the work of actually building the MimeMessage.
    `DataSourceResolver` | `getDataSourceResolver()` Get the data source resolver.
    `void` | `setDataSourceResolver(DataSourceResolver dataSourceResolver)` Set the data source resolver.

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

      `embed, embed, embed, embed, embed, embed, setHtmlMsg, setMsg, setTextMsg`

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

      `addPart, addPart, addPart, attach, attach, attach, attach, attach, attach, createBodyPart, createMimeMultipart, getContainer, getPrimaryBodyPart, getSubType, init, isBoolHasAttachments, isInitialized, setBoolHasAttachments, setInitialized, setSubType`

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

- - ### Field Detail

    - #### REGEX_IMG_SRC

          public static final String REGEX_IMG_SRC

      Regexp for extracting `<img>` tags
      See Also:
        Constant Field Values

    - #### REGEX_SCRIPT_SRC

          public static final String REGEX_SCRIPT_SRC

      regexp for extracting `<script>` tags
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ImageHtmlEmail

          public ImageHtmlEmail()

  - ### Method Detail

    - #### getDataSourceResolver

          public DataSourceResolver getDataSourceResolver()

      Get the data source resolver.
      Returns:
        the resolver

    - #### setDataSourceResolver

          public void setDataSourceResolver(DataSourceResolver dataSourceResolver)

      Set the data source resolver.
      Parameters:
        `dataSourceResolver` - the resolver

    - #### buildMimeMessage

          public void buildMimeMessage()
                                throws EmailException

      Does the work of actually building the MimeMessage.
      Overrides:
        `buildMimeMessage` in class `HtmlEmail`
      Throws:
        `EmailException` - building the MimeMessage failed
      See Also:
        `HtmlEmail.buildMimeMessage()`

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