1 16 package dlog4j.util.mail; 17 18 import java.util.Date ; 19 20 import javax.servlet.ServletException ; 21 22 import org.apache.struts.action.ActionServlet; 23 import org.apache.struts.action.PlugIn; 24 import org.apache.struts.config.ModuleConfig; 25 26 43 public class MailSenderPlugin extends Mailer implements PlugIn { 44 45 protected String mail; 46 protected String host; 47 protected int port = 25; 48 protected String username; 49 protected String password; 50 51 private ActionServlet servlet; 52 53 56 public void init(ActionServlet servlet, ModuleConfig config) throws ServletException { 57 this.servlet = servlet; 58 mailer = this; 59 } 60 61 68 public void send(final String sendername, 69 final String [] mails, 70 final String title, 71 final String content) 72 { 73 new Thread (){ 74 public void run(){ 75 MailSender sender = MailSender.getHtmlMailSender(host,port,username,password); 76 try{ 77 sender.setSubject(title); 78 sender.setSendDate(new Date ()); 79 sender.setMailFrom(mail, sendername); 80 sender.setMailContent(content); 81 sender.setMailTo(mails, "to"); 82 sender.sendMail(); 83 }catch(Exception e){ 84 servlet.log("发送邮件失败,title="+title+",content="+content,e); 85 } 86 } 87 }.start(); 88 } 89 90 93 public void destroy() { 94 } 95 96 public String getHost() { 97 return host; 98 } 99 public void setHost(String host) { 100 this.host = host; 101 } 102 public String getMail() { 103 return mail; 104 } 105 public void setMail(String mail) { 106 this.mail = mail; 107 } 108 public String getPassword() { 109 return password; 110 } 111 public void setPassword(String password) { 112 this.password = password; 113 } 114 public int getPort() { 115 return port; 116 } 117 public void setPort(int port) { 118 this.port = port; 119 } 120 public String getUsername() { 121 return username; 122 } 123 public void setUsername(String username) { 124 this.username = username; 125 } 126 } 127 | Popular Tags |