1 16 17 package org.apache.jetspeed.modules.actions; 18 19 import java.io.StringWriter ; 21 import java.util.Properties ; 22 import java.util.Locale ; 23 24 import org.apache.jetspeed.services.resources.JetspeedResources; 26 import org.apache.jetspeed.services.TemplateLocator; 27 import org.apache.jetspeed.services.JetspeedSecurity; 28 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 29 import org.apache.jetspeed.services.logging.JetspeedLogger; 30 import org.apache.jetspeed.om.security.JetspeedUser; 31 32 import org.apache.turbine.modules.Action; 34 import org.apache.turbine.services.localization.Localization; 35 import org.apache.turbine.services.velocity.TurbineVelocity; 36 import org.apache.turbine.util.RunData; 37 import org.apache.turbine.util.DynamicURI; 38 import org.apache.turbine.util.mail.SimpleEmail; 39 40 import org.apache.velocity.context.Context; 42 43 53 public class SendNewUserNotificationEmail extends Action 54 { 55 58 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(SendNewUserNotificationEmail.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("pane0", "Security" ) 65 .addPathInfo("select-panel2", "User") 66 .addPathInfo("entityid", user.getUserName() ) 67 .addQueryData("mode","update"); 68 try 69 { 70 StringWriter email_body = new StringWriter (); 72 SimpleEmail se = new SimpleEmail(); 73 Context emailContext = TurbineVelocity.getContext(); 74 emailContext.put( "data", data ); 75 emailContext.put( "user", user ); 76 emailContext.put( "config",new JetspeedResources()); 77 emailContext.put( "userurl",url); 78 emailContext.put( "email",se); 79 80 String language = JetspeedResources.getString("newuser.notification.language","en"); 82 String country = JetspeedResources.getString("newuser.notification.country","US"); 83 Locale locale = new Locale (language,country); 84 85 String templateFile = JetspeedResources.getString("newuser.notification.email.template"); 86 String templatePath = TemplateLocator.locateEmailTemplate(data, templateFile, locale); 87 TurbineVelocity.handleRequest(emailContext, templatePath, email_body); 88 89 se.setMsg(email_body.toString()); 90 91 Properties props = System.getProperties(); 92 String mailServerMachine = JetspeedResources.getString( "mail.server" ); 93 props.put ( "mail.host", mailServerMachine ); 94 props.put("mail.smtp.host", mailServerMachine); 95 96 se.send(); 97 98 data.setMessage (Localization.getString(data, "SENDCONFIRMATIONEMAIL_SENT")); 99 } catch ( Exception e ) 100 { 101 String errorTitle = Localization.getString(data, "SENDCONFIRMATIONEMAIL_ERROR") ; 102 String errorMessage = errorTitle + e.getMessage(); 103 104 logger.error( errorMessage, e ); 105 data.setMessage ( errorTitle + errorMessage ); 106 } 107 } 108 } 109 | Popular Tags |