Commons Email
  1. Commons Email
  2. EMAIL-35

[email] Embedding raw DataSource Attachments

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      I kick myself for not submitting this prior to 1.0. An important feature
      missing from org.apache.commons.mail.HtmlEmail is the ability to embed an
      arbitrary DataSource object. The current API only allows you to embed from a
      URL. My usage of CommonsEmail often includes the generation of image data
      on-the-fly, where it does not exist at a pre-defined URL.

      I propose the addition of a key method:

      public String embed(DataSource datasource, String name, String cid) throws
      EmailException

      This will allow us to attach our own datasources in addition to defining our own
      content-ids. Helper methods can be created to auto-generate CIDs when needed
      and allow for backwards compatability. I've found that being able to provide my
      own defined CIDs has been very helpful in referencing them in my velocity email
      templates.

      I will attach the current EnhancedHtmlEmail class that I have been using for a
      year or so. It extends HtmlEmail to provide the methods explained above. I
      would hope to have this capability introduced into the HtmlEmail class.

      Feel free to contact me to discuss further! Thanks.

      1. ASF.LICENSE.NOT.GRANTED--EnhancedHtmlEmail.java
        3 kB
        Brandon Wolfe
      2. HtmlEmail.patch
        6 kB
        Ben Speakmon
      3. HtmlEmailTest.patch
        1 kB
        Ben Speakmon

        Issue Links

          Activity

          Hide
          Brandon Wolfe added a comment -

          Created an attachment (id=16543)
          Proposed enhancement methods for HtmlEmail class. Integrate into the API...

          Show
          Brandon Wolfe added a comment - Created an attachment (id=16543) Proposed enhancement methods for HtmlEmail class. Integrate into the API...
          Hide
          dion gillard added a comment -

          This requires an extra dependency on commons-lang which I'd prefer not to have,
          if possible.

          Got another simpler way of getting the cid?

          Show
          dion gillard added a comment - This requires an extra dependency on commons-lang which I'd prefer not to have, if possible. Got another simpler way of getting the cid?
          Hide
          Piero Ottuzzi added a comment -

          (In reply to comment #2)
          > This requires an extra dependency on commons-lang which I'd prefer not to have,
          > if possible.
          >
          > Got another simpler way of getting the cid?

          You can use EmailUtils.randomAlphabetic() to get what you are looking for.

          Show
          Piero Ottuzzi added a comment - (In reply to comment #2) > This requires an extra dependency on commons-lang which I'd prefer not to have, > if possible. > > Got another simpler way of getting the cid? You can use EmailUtils.randomAlphabetic() to get what you are looking for.
          Hide
          Ben Speakmon added a comment -

          I'm attaching a patch against the current HtmlEmail.java that adds Brandon's changes as well as some added documentation. There's also a patch for HtmlEmailTest updating testEmbed() to exercise the new embed() methods.

          Show
          Ben Speakmon added a comment - I'm attaching a patch against the current HtmlEmail.java that adds Brandon's changes as well as some added documentation. There's also a patch for HtmlEmailTest updating testEmbed() to exercise the new embed() methods.
          Hide
          Morten Hattesen added a comment -

          Any chance this patch could be applied sometime soon, so a version 1.1 could be made available?

          Show
          Morten Hattesen added a comment - Any chance this patch could be applied sometime soon, so a version 1.1 could be made available?
          Hide
          Ben Speakmon added a comment -

          I just got in a fix for this. In addition to embedding plain DataSources, you can also now embed Files directly.

          Show
          Ben Speakmon added a comment - I just got in a fix for this. In addition to embedding plain DataSources, you can also now embed Files directly.

            People

            • Assignee:
              Ben Speakmon
              Reporter:
              Brandon Wolfe
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development