package com.springemail;
import java.io.File;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.javamail.MimeMessageHelper;
public class SimpleHtmlMailSender extends BaseMailSender {
private static final Log log = LogFactory.getLog(SimpleHtmlMailSender.class);
public void sendMessage() throws MessagingException {
MimeMessage msg = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(msg, true, "GB2312");
helper.setTo(to);
helper.setFrom(from);
helper.setSubject(subject);
StringBuffer bf = new StringBuffer();
bf.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">")
.append("<head>")
.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />")
.append("<title>欧尚卡</title>")
.append("<style type=\"text/css\">")
.append("<!--")
.append("body {margin-top: 0px;background-color: #ffffff;}")
.append("body,td,th {font-family: 黑体;font-size: 13px;color: #000000;}")
.append("#Layer1 {position:absolute;left:638px;top:167px;width:236px;height:78px;z-index:1;}")
.append(".STYLE3{color: #FF9900;font-weight: bold;}")
.append("a:link{color: #FF9900;}")
.append("a:visited {color: #FF9900;}")
.append("a:hover{color: #FF9900;}")
.append("a:active {color: #FF9900;}")
.append(".STYLE4 {font-size: 16px;font-weight: bold;}")
.append("-->")
.append("</style></head>")
.append("<body><p> </p>")
.append("<table width=\"840\" border=\"0\" align=\"center\">")
.append("<tr valign=\"middle\"> ")
.append("<td colspan =\"3\"><img src=\"images/AU_header.jpg\" width=\"840\" height=\"95\"> </td>")
.append("<tr valign=\"middle\"> ")
.append("<td width=\"257\"> </td>")
.append("<td width=\"256\"> </td>")
.append("<td width=\"124\"></td>")
.append("<td width=\"228\"> </td>")
.append("</tr>")
.append("</table>")
.append("<table width=\"850\" border=\"0\" align=\"center\">")
.append("<tr>")
.append("<td>")
.append("</td>")
.append("</tr>")
.append("<tr>").append("<td> </td>").append("</tr>")
.append("</table>")
.append("<table width=\"840\" border=\"0\" align=\"center\">")
.append("<tr>")
.append("<td width=\"384\" height=\"94\" valign=\"top\"> ")
.append("<p><br />")
.append("尊敬的XXX先生/小姐:<br />")
.append(" 您好!感谢您使用我行信用卡,特别呈上您欧尚卡账户XX年XX月对账单,请核对并按时缴款。 <br />")
.append("</p>").append("</td>")
.append("<td width=\"446\" valign=\"top\"> ")
.append("<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#FF0000\">")
.append("<tr><td>")
.append("<table width=\"100%\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\" bordercolor=\"#FF0000\" style=\"border-collapse:collapse\">")
.append("<tr><td width=\"33%\" bgcolor=\"#FFCCCC\">")
.append("<div align=\"right\">信用额度</div>")
.append("</td><td width=\"67%\" bgcolor=\"#FFFFFF\"> </td></tr>")
.append("</table></td></tr></body></html>");
helper.setText(bf.toString(),true);
FileSystemResource img = new FileSystemResource(new File("H:/双币电子账单系统/AU/AU/images/AU_header.jpg"));
helper.addInline("AU_header",img);
sender.send(msg);
}
public static void main(String args[]) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"mailSender.xml");
SimpleHtmlMailSender sender = (SimpleHtmlMailSender) ctx
.getBean("messageSender");
try {
sender.sendMessage();
} catch (MessagingException e) {
log.error(e);
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
SpringEmail.rar (19个子文件)
SpringEmail
.project 387B
bin
log4j.properties 307B
com
springemail
Crack.class 3KB
BaseMailSender.class 911B
SimpleHtmlMailSender.class 5KB
mailSender.xml 995B
.settings
org.eclipse.jdt.core.prefs 629B
src
log4j.properties 307B
com
springemail
BaseMailSender.java 528B
Crack.java 2KB
SimpleHtmlMailSender.java 4KB
mailSender.xml 995B
.classpath 642B
lib
commons-logging.jar 52KB
activation.jar 62KB
mail.jar 339KB
xercesImpl-2.6.2.jar 987KB
log4j-1.2.14.jar 359KB
spring.jar 2.81MB
共 19 条
- 1
资源评论
- Eric5201232014-09-05终于找到一个可以用的了,谢谢楼主!
mizone_1982
- 粉丝: 42
- 资源: 123
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功