Package 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
  Description
  `static final String`
  `REGEX_IMG_SRC`
  Regexp for extracting `<img>` tags
  `static final 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
  Description
  `ImageHtmlEmail()`
  Constructs a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `buildMimeMessage()`
  Does the work of actually building the MimeMessage.
  `DataSourceResolver`
  `getDataSourceResolver()`
  Gets the data source resolver.
  `void`
  `setDataSourceResolver(DataSourceResolver dataSourceResolver)`
  Sets the data source resolver.

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

  `embed, embed, embed, embed, embed, embed, getHtml, getText, setHtmlMsg, setMsg, setTextMsg`

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

  `addPart, addPart, addPart, attach, 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, getAuthenticator, getBccAddresses, getBounceAddress, getCcAddresses, getCharsetName, getContent, getContentType, getEmailBody, getFromAddress, getHeader, getHeaders, getHostName, getMailSession, getMessage, getMimeMessage, getPopHost, getPopPassword, getPopUserName, getReplyToAddresses, getSentDate, getSmtpPort, getSocketConnectionTimeout, getSocketTimeout, getSslSmtpPort, getSubject, getToAddresses, isDebug, isPopBeforeSmtp, isSendPartial, isSSL, isSSLCheckServerIdentity, isSSLOnConnect, isStartTLSEnabled, isStartTLSRequired, isTLS, send, sendMimeMessage, setAuthentication, setAuthenticator, setBcc, setBounceAddress, setCc, setCharset, setContent, setContent, setContent, setContentType, setDebug, setFrom, setFrom, setFrom, setFromAddress, setHeaders, setHostName, setMailSession, setMailSessionFromJNDI, setMessage, setPopBeforeSmtp, setPopBeforeSmtp, setPopHost, setPopPassword, setPopUsername, setReplyTo, setSendPartial, setSentDate, setSmtpPort, setSocketConnectionTimeout, setSocketConnectionTimeout, setSocketTimeout, 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 Details

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

  - ### ImageHtmlEmail

    public ImageHtmlEmail()
    Constructs a new instance.

- ## Method Details

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

  - ### getDataSourceResolver

    public DataSourceResolver getDataSourceResolver()
    Gets the data source resolver.
    Returns:
      the resolver

  - ### setDataSourceResolver

    public void setDataSourceResolver(DataSourceResolver dataSourceResolver)
    Sets the data source resolver.
    Parameters:
      `dataSourceResolver` - the resolver