我们在发送邮件的时候,如果使用HTML在邮件内容中嵌入图片,<img src='。。。'/>,这经常会被邮件客户端软件或者网页阻止显示,这主要也是安全方面的考虑。
但其实我们也可以直接将图片本身直接嵌在邮件内容中,而是用 Commons-Email 可以轻松完成这个功能。
public static void SendPwdResetMail(String email, String account, String resetKey) {
try {
HtmlEmail body = _NewMailInstance(Arrays.asList(email));
body.setSubject("ddddddddddd");
File logo = new File(rootPath+"img"+File.separator+"logo.gif");
String cid = body.embed(logo, "image file");
body.setHtmlMsg("ddddddddddddddd<img src=""+cid
+"" alt="hhhhh" border="0"/>");
body.send();
} catch (EmailException e) {
throw new RuntimeException("Unabled to send mail", e);
}
}