1 15 package com.openedit.modules.email; 16 17 import javax.mail.MessagingException ; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 22 import com.openedit.OpenEditException; 23 import com.openedit.WebPageRequest; 24 import com.openedit.modules.BaseModule; 25 import com.openedit.page.Page; 26 27 30 public class SendMailModule extends BaseModule 31 { 32 private static final Log log = LogFactory.getLog(SendMailModule.class); 33 public static final String EMAIL_SETTINGS = "emailsettings"; 34 private PostMail postMail; 35 36 public PostMail getPostMail() { 37 return postMail; 38 } 39 40 public void setPostMail(PostMail postMail) { 41 this.postMail = postMail; 42 } 43 44 public SendMailModule() 45 { 46 47 } 48 49 private TemplateWebEmail createTemplateEmail( WebPageRequest inContext) throws OpenEditException 50 { 51 TemplateWebEmail email = getPostMail().getTemplateWebEmail(); email.loadSettings(inContext, getPageManager()); 53 return email; 54 } 55 56 63 public void sendEmail(WebPageRequest inContext)throws OpenEditException 64 { 65 66 if ( inContext.getPageValue(EMAIL_SETTINGS) == null) 67 { 68 inContext.putPageValue(EMAIL_SETTINGS,createTemplateEmail(inContext)); 69 } 70 TemplateWebEmail webmail = (TemplateWebEmail)inContext.getPageValue(SendMailModule.EMAIL_SETTINGS); 71 webmail.setPostMail(postMail); 72 sendEmail(inContext, webmail); 73 } 74 75 81 82 protected void sendEmail(WebPageRequest inReq, WebEmail inWebmail) throws OpenEditException 83 { 84 Page page = inReq.getPage(); 85 try 87 { 88 inWebmail.send(); 89 } 90 catch (MessagingException e) 91 { 92 log.error(e); 93 String errorpage = page.get("error_page"); 94 if (errorpage == null || errorpage.length() <= 0) 95 errorpage = inReq.getRequestParameter( "error_page" ); 96 if ( errorpage != null) 97 { 98 inReq.redirect( errorpage ); 99 return; 100 } 101 102 } 103 String successpage = page.get("success_page"); 104 if (successpage == null || successpage.length() <= 0) 105 successpage = inReq.getRequestParameter( "success_page" ); 106 if ( successpage != null) 107 { 108 inReq.redirect( successpage ); 109 } 110 } 111 112 } 113 | Popular Tags |