protected void addEmbeddables(HtmlEmail email) throws EmailException { for (Entry<String, DataSource> entry : toEmbed.entrySet()) { String key = entry.getKey(); String cid = email.embed(entry.getValue(), key); with(key, "cid:" + cid); } }
public void sendHtmlMail(String toEmail, String HtmlMsg) { HtmlEmail email = new HtmlEmail(); email.setCharset("UTF-8"); email.setHostName("smtp.sina.com"); email.setSmtpPort(25); email.setAuthentication("*****@*****.**", "tianren"); email.setTLS(true); try { email.addTo(toEmail); email.setFrom("*****@*****.**"); email.setSubject("Sky Movie"); // Title email.setMsg("Ticket Order Info"); URL url = new URL("http://localhost:8888/TianRen/uploadAd/31049534581071.gif"); String cid = email.embed(url, "TianRen Logo"); email.setHtmlMsg( "<html><a href='http://localhost:8888/TianRen/index.jsp'><img src=\"cid:" + cid + "\" height=\"75\"></a><br/>" + HtmlMsg + "</html>"); email.send(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (EmailException e) { // TODO Auto-generated catch block e.printStackTrace(); } }