ITPub博客

首页 > IT基础架构 > 网络安全 > 利用spring-mail 写的超级smart-mail发送器

利用spring-mail 写的超级smart-mail发送器

原创 网络安全 作者:biqing0427 时间:2007-12-04 16:48:19 0 删除 编辑

[@more@]

应用spring:

import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;

lib:

javamail-1.4.1:mail.jar

jaf-1.1:activation.jar

import org.springframework.mail.MailException; import org.springframework.mail.MailSender; import org.springframework.mail.SimpleMailMessage; public class SenderManagerImpl implements SenderManager { private MailSender mailSender; private SimpleMailMessage message; public void placeMessage(Message message) { SimpleMailMessage msg = new SimpleMailMessage(this.message); if (message.getMail() != null) msg.setTo(message.getMail()); if (message.getContent() != null) msg.setText(message.getContent()); if (message.getSubject() != null) msg.setSubject(message.getSubject()); if (message.getCc() != null) msg.setCc(message.getCc()); if (message.getCcMore() != null) msg.setCc(message.getCcMore()); try { mailSender.send(msg); } catch (MailException e) { System.out.println(e.getMessage()); System.out.println(e.getStackTrace()); } } public MailSender getMailSender() { return mailSender; } public void setMailSender(MailSender mailSender) { this.mailSender = mailSender; } public SimpleMailMessage getMessage() { return message; } public void setMessage(SimpleMailMessage message) { this.message = message; }; } public class Message { String name = ""; String mail = ""; String content = ""; String subject = ""; String cc = ""; String[] ccMore = null; public Message() { } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getMail() { return mail; } public void setMail(String mail) { this.mail = mail; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getSubject() { return subject; } public void setSubject(String subject) { this.subject = subject; } public String getCc() { return cc; } public void setCc(String cc) { this.cc = cc; } public String[] getCcMore() { return ccMore; } public void setCcMore(String[] ccMore) { this.ccMore = ccMore; }; } imap.net-m.de XWZHOU88!@#$ hzhou hero.zhou@net-m.de spring-mail public void testMail(){ ApplicationContext ctx=new FileSystemXmlApplicationContext("conf/spring/bean.xml"); SenderManager senderManager = (SenderManager) ctx.getBean("senderManager"); Message message = new Message(); message.setContent("this is my first mailProcess using spring-mail"); message.setMail("biqing0427@163.com"); message.setName("me"); message.setSubject("hello hero,this is me"); senderManager.placeMessage(message); //senderManager. }

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9879276/viewspace-988490/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    24
  • 访问量
    11581