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

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

Introduction

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

Prototype

public String embed(final File file) throws EmailException 

Source Link

Document

Embeds a file in the HTML.

Usage

From source file:com.pax.pay.trans.receipt.paperless.AReceiptEmail.java

public int sendHtmlEmail(EmailInfo emailInfo, String emailAddress, String subject, String content, Bitmap pic) {
    String placeHolder = "<img/>";
    String htmlMsg = "<html><body>" + placeHolder + "</body></html>";
    try {//  w  ww  .j  a  va2  s . c o  m
        ImageHtmlEmail email = new ImageHtmlEmail();

        setBaseInfo(emailInfo, email);
        File file = Convert(pic, "receipt_tmp.jpg");
        email.setDataSourceResolver(new DataSourceFileResolver(file));
        String cid = email.embed(file); // cid
        String img = "<img src='cid:" + cid + "'/>"; // img?cid
        htmlMsg = htmlMsg.replace(placeHolder, img); // ?html??

        email.setSubject(subject);
        email.setTextMsg(content);
        email.setHtmlMsg(htmlMsg);
        email.addTo(emailAddress);
        email.send();
    } catch (EmailException | IOException e) {
        e.printStackTrace();
        return -1;
    }
    return 0;
}