Example usage for org.apache.commons.mail HtmlEmail CID_LENGTH

List of usage examples for org.apache.commons.mail HtmlEmail CID_LENGTH

Introduction

In this page you can find the example usage for org.apache.commons.mail HtmlEmail CID_LENGTH.

Prototype

int CID_LENGTH

To view the source code for org.apache.commons.mail HtmlEmail CID_LENGTH.

Click Source Link

Document

Definition of the length of generated CID's.

Usage

From source file:immf.MyHtmlEmail.java

/**
 * Embeds a file in the HTML. This implementation delegates to
 * {@link #embed(File, String)}.//from ww  w  .ja  v a2 s . c o  m
 *
 * @param file The <code>File</code> object to embed
 * @return A String with the Content-ID of the file.
 * @throws EmailException when the supplied <code>File</code> cannot be
 * used; also see {@link javax.mail.internet.MimeBodyPart} for definitions
 *
 * @see #embed(File, String)
 * @since 1.1
 */
public String embed(File file) throws EmailException {
    String cid = randomAlphabetic(HtmlEmail.CID_LENGTH).toLowerCase();
    return embed(file, cid);
}

From source file:immf.MyHtmlEmail.java

/**
 * Embeds the specified <code>DataSource</code> in the HTML using a
 * randomly generated Content-ID. Returns the generated Content-ID string.
 *
 * @param dataSource the <code>DataSource</code> to embed
 * @param name the name that will be set in the filename header field
 * @return the generated Content-ID for this <code>DataSource</code>
 * @throws EmailException if the embedding fails or if <code>name</code> is
 * null or empty/*ww w. java  2s  . c om*/
 * @see #embed(DataSource, String, String)
 * @since 1.1
 */
public String embed(DataSource dataSource, String name) throws EmailException {
    // check if the DataSource has already been attached;
    // if so, return the cached CID value.
    if (inlineEmbeds.containsKey(name)) {
        InlineImage ii = (InlineImage) inlineEmbeds.get(name);
        // make sure the supplied URL points to the same thing
        // as the one already associated with this name.
        if (dataSource.equals(ii.getDataSource())) {
            return ii.getCid();
        } else {
            throw new EmailException("embedded DataSource '" + name + "' is already bound to name "
                    + ii.getDataSource().toString() + "; existing names cannot be rebound");
        }
    }

    String cid = randomAlphabetic(HtmlEmail.CID_LENGTH).toLowerCase();
    return embed(dataSource, name, cid);
}