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

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

Introduction

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

Prototype

public String embed(final DataSource dataSource, final String name) throws EmailException 

Source Link

Document

Embeds the specified DataSource in the HTML using a randomly generated Content-ID.

Usage

From source file:org.ploin.pmf.impl.MailSender.java

/**
 *
 * @param email - the email object//from   w w  w . jav  a 2 s.c o  m
 * @param map - the map with the values and variables
 * @param mail - the mail as string
 */
private void setEmbeds(HtmlEmail email, Map<String, String> map, String mail) throws MailFactoryException {
    try {
        for (String key : map.keySet()) {
            if (key.startsWith("embed")) {
                URL url = null;
                String urlString = map.get(key);
                url = new URL(urlString);
                if (url != null) {
                    String cid = email.embed(url, key);
                    String htmlVal = "cid:" + cid;
                    mail = mail.replaceAll(key, htmlVal);
                }
            }
        }
    } catch (Exception e) {
        throw new MailFactoryException(e);
    }
}