HtmlEmail email = new HtmlEmail();
email.setDebug(true);
email.setHostName("smtp.sina.com");
email.setAuthentication("发送邮件帐号", "发送邮件密码");
email.setCharset("UTF-8");
try {
email.setFrom("发送邮件帐号", "用户名", "UTF-8");//中文内容不设置编码格式会有乱码
email.addTo("接受邮件帐号", "用户名", "UTF-8");
email.setSubject("主题");
String cid = email.embed(new File("D:/1938014-1.jpg"));
email.setHtmlMsg("<div style=‘color:red;font-size:200px‘>HTML内容</div> <img src=‘cid:" + cid + "‘ />");
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
时间: 2024-10-08 21:35:24