1 16 17 package org.apache.jetspeed.modules.actions; 18 19 import java.io.StringWriter ; 21 import java.util.Properties ; 22 23 import org.apache.jetspeed.services.TemplateLocator; 25 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 26 import org.apache.jetspeed.services.logging.JetspeedLogger; 27 import org.apache.jetspeed.services.resources.JetspeedResources; 28 import org.apache.jetspeed.services.JetspeedSecurity; 29 import org.apache.jetspeed.om.security.JetspeedUser; 30 31 import org.apache.turbine.modules.Action; 33 import org.apache.turbine.services.localization.Localization; 34 import org.apache.turbine.services.velocity.TurbineVelocity; 35 import org.apache.turbine.util.RunData; 36 import org.apache.turbine.util.DynamicURI; 37 import org.apache.turbine.util.mail.SimpleEmail; 38 39 import org.apache.velocity.context.Context; 41 42 52 public class SendConfirmationEmail extends Action 53 { 54 55 58 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(SendConfirmationEmail.class.getName()); 59 60 public void doPerform( RunData data ) throws Exception 61 { 62 JetspeedUser user = JetspeedSecurity.getUser(data.getParameters().getString("username", "")); 63 DynamicURI url = new DynamicURI(data) 64 .addPathInfo(JetspeedResources.PATH_TEMPLATE_KEY, "ConfirmRegistration") 65 .addPathInfo("username", user.getUserName()) 66 .addPathInfo("secretkey", user.getConfirmed()) 67 .addPathInfo("password", user.getPassword()); 68 try 69 { 70 StringWriter email_body = new StringWriter (); 72 Context emailContext = TurbineVelocity.getContext(data); 73 SimpleEmail se = new SimpleEmail(); 74 emailContext.put( "data", data ); 75 emailContext.put( "user", user ); 76 emailContext.put("config",new JetspeedResources()); 77 emailContext.put("urltojetspeed",url); 78 emailContext.put("email",se); 79 String templateFile = JetspeedResources.getString("newuser.confirm.email.template"); 80 String templatePath = TemplateLocator.locateEmailTemplate(data, templateFile); 81 TurbineVelocity.handleRequest(emailContext, templatePath, email_body); 82 83 se.setMsg( email_body.toString() ); 84 85 Properties props = System.getProperties(); 86 String mailServerMachine = JetspeedResources.getString( "mail.server" ); 87 props.put ( "mail.host", mailServerMachine ); 88 props.put("mail.smtp.host", mailServerMachine); 89 90 se.send(); 91 92 data.setMessage (Localization.getString(data, "SENDCONFIRMATIONEMAIL_SENT")); 93 } 94 catch ( Exception e ) 95 { 96 String errorTitle = Localization.getString("SENDCONFIRMATIONEMAIL_ERROR") ; 97 String errorMessage = errorTitle + e.getMessage(); 98 99 logger.error( errorMessage, e ); 100 data.setMessage ( errorTitle + errorMessage ); 101 } 102 } 103 } 104 | Popular Tags |