View Javadoc

1   /*
2    * Copyright 2006-2008 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.kns.service.impl;
17  
18  import java.util.Arrays;
19  import java.util.Collections;
20  import java.util.Iterator;
21  import java.util.Set;
22  
23  import org.kuali.rice.kns.mail.InvalidAddressException;
24  import org.kuali.rice.kns.mail.MailMessage;
25  import org.kuali.rice.kns.service.MailService;
26  import org.springframework.mail.MailException;
27  import org.springframework.mail.MailSender;
28  import org.springframework.mail.SimpleMailMessage;
29  
30  public class MailServiceImpl implements MailService {
31      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MailServiceImpl.class);
32  
33      private MailSender mailSender;
34      private String batchMailingList;
35      private String incidentMailingList;
36      
37      /**
38       * 
39       */
40      public MailServiceImpl() {
41          super();
42      }
43  
44      public void sendMessage(MailMessage message) throws InvalidAddressException {
45          LOG.debug("sendMessage() started");
46  
47          // Send email
48          SimpleMailMessage smm = new SimpleMailMessage();
49          smm.setTo( (String[])message.getToAddresses().toArray(new String[message.getToAddresses().size()]) );
50          smm.setBcc( (String[])message.getBccAddresses().toArray(new String[message.getBccAddresses().size()]) );
51          smm.setCc( (String[])message.getCcAddresses().toArray(new String[message.getCcAddresses().size()]) );
52          smm.setSubject(message.getSubject());
53          smm.setText(message.getMessage());
54          smm.setFrom(message.getFromAddress());
55  
56          try {
57          	if ( LOG.isDebugEnabled() ) {
58          		LOG.debug( "About to send message: " + smm.toString() );
59          	}
60              mailSender.send(smm);
61          }
62          catch (MailException e) {
63              throw new InvalidAddressException(e);
64          }
65      }
66  
67      public void setMailSender(MailSender ms) {
68          mailSender = ms;
69      }
70  
71      /**
72       * Sets the batchMailingList attribute value.
73       * @param batchMailingList The batchMailingList to set.
74       */
75      public void setBatchMailingList(String batchMailingList) {
76          this.batchMailingList = batchMailingList;
77      }
78  
79      /**
80       * @see org.kuali.rice.kns.service.MailService#getBatchMailingList()
81       */
82      public String getBatchMailingList() {
83          return batchMailingList;
84      }
85      
86  	/**
87  	 * @return the incidentMailingList
88  	 */
89  	public String getIncidentMailingList() {
90  		return this.incidentMailingList;
91  	}
92  
93  	/**
94  	 * @param incidentMailingList the incidentMailingList to set
95  	 */
96  	public void setIncidentMailingList(String incidentMailingList) {
97  		this.incidentMailingList = incidentMailingList;
98  	}
99  
100 }