001 package railo.runtime.net.smtp; 002 003 import javax.mail.Transport; 004 005 import railo.commons.io.SystemUtil; 006 import railo.runtime.net.smtp.SMTPClient.MimeMessageAndSession; 007 008 009 public final class SMTPSender extends Thread { 010 011 private boolean hasSended=false; 012 private Throwable throwable; 013 private Object lock; 014 private String host; 015 private int port; 016 private String user; 017 private String pass; 018 private MimeMessageAndSession mmas; 019 020 public SMTPSender(Object lock, MimeMessageAndSession mmas, String host, int port, String user, String pass) { 021 this.lock=lock; 022 this.mmas=mmas; 023 024 this.host=host; 025 this.port=port; 026 this.user=user; 027 this.pass=pass; 028 } 029 030 /** 031 * @see java.lang.Thread#run() 032 */ 033 public void run() { 034 Transport transport = null; 035 try { 036 transport = mmas.session.transport;//SMTPConnectionPool.getTransport(session,host,port,user,pass); 037 // connect 038 if(!transport.isConnected()) 039 transport.connect(host,port,user,pass); 040 041 042 mmas.message.saveChanges(); 043 transport.sendMessage(mmas.message, mmas.message.getAllRecipients()); 044 hasSended=true; 045 } 046 catch (Throwable t) { 047 this.throwable=t; 048 } 049 finally { 050 try {SMTPConnectionPool.releaseSessionAndTransport(mmas.session);}catch (Throwable t) {} 051 SystemUtil.notify(lock); 052 } 053 } 054 055 /** 056 * @return the messageExpection 057 */ 058 public Throwable getThrowable() { 059 return throwable; 060 } 061 062 /** 063 * @return is message sended 064 */ 065 public boolean hasSended() { 066 return hasSended; 067 } 068 069 }