View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.service.impl;
17  
18  import javax.mail.MessagingException;
19  
20  import org.kuali.rice.core.api.CoreConstants;
21  import org.kuali.rice.core.api.mail.MailMessage;
22  import org.kuali.rice.core.api.mail.Mailer;
23  import org.kuali.rice.krad.exception.InvalidAddressException;
24  import org.kuali.rice.krad.service.KRADServiceLocator;
25  import org.kuali.rice.krad.service.MailService;
26  import org.kuali.rice.krad.util.KRADConstants;
27  
28  public class MailServiceImpl implements MailService {
29      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MailServiceImpl.class);
30  
31      private String batchMailingList;
32      private Mailer mailer;
33      
34      /**
35       * The injected Mailer.
36       */
37      public void setMailer(Mailer mailer) {
38      	this.mailer = mailer;
39      }
40      
41      /**
42       * 
43       */
44      public MailServiceImpl() {
45          super();
46      }
47  
48      /**
49       * Sets the batchMailingList attribute value.
50       * @param batchMailingList The batchMailingList to set.
51       */
52      public void setBatchMailingList(String batchMailingList) {
53          this.batchMailingList = batchMailingList;
54      }
55  
56      /**
57       * @see org.kuali.rice.krad.service.MailService#getBatchMailingList()
58       */
59      public String getBatchMailingList() {
60          return batchMailingList;
61      }
62  
63  	/**
64  	 * This overridden method ...
65  	 * @throws MessagingException 
66  	 * 
67  	 * @see org.kuali.rice.krad.service.MailService#sendMessage(org.kuali.rice.core.api.mail.MailMessage)
68  	 */
69  	@Override
70  	public void sendMessage(MailMessage message) throws InvalidAddressException, MessagingException {
71  		mailer.sendEmail(composeMessage(message));		
72  	}
73  	
74      protected MailMessage composeMessage(MailMessage message){
75          MailMessage mm = new MailMessage();
76          String app = KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(CoreConstants.Config.APPLICATION_ID);
77          String env = KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(KRADConstants.ENVIRONMENT_KEY);
78          
79          mm.setToAddresses(message.getToAddresses());
80          mm.setBccAddresses(message.getBccAddresses());
81          mm.setCcAddresses(message.getCcAddresses());
82          mm.setSubject(app + " " + env + ": " + message.getSubject());
83          mm.setMessage(message.getMessage());
84          mm.setFromAddress(message.getFromAddress());
85          return mm;
86      }
87  }