01: /*
02: * Copyright 2006-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.core.service.impl;
17:
18: import java.util.Iterator;
19: import java.util.Set;
20:
21: import org.kuali.core.mail.InvalidAddressException;
22: import org.kuali.core.mail.MailMessage;
23: import org.kuali.core.service.MailService;
24: import org.springframework.mail.MailException;
25: import org.springframework.mail.MailSender;
26: import org.springframework.mail.SimpleMailMessage;
27:
28: public class MailServiceImpl implements MailService {
29: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
30: .getLogger(MailServiceImpl.class);
31:
32: private MailSender mailSender;
33: private String batchMailingList;
34:
35: /**
36: *
37: */
38: public MailServiceImpl() {
39: super ();
40: }
41:
42: private String[] setConverter(Set s) {
43: String[] out = new String[s.size()];
44:
45: int x = 0;
46: for (Iterator iter = s.iterator(); iter.hasNext();) {
47: String element = (String) iter.next();
48: out[x] = element;
49: x++;
50: }
51: return out;
52: }
53:
54: public void sendMessage(MailMessage message)
55: throws InvalidAddressException {
56: LOG.debug("sendMessage() started");
57:
58: // Send email
59: SimpleMailMessage smm = new SimpleMailMessage();
60: smm.setTo(setConverter(message.getToAddresses()));
61: smm.setBcc(setConverter(message.getBccAddresses()));
62: smm.setCc(setConverter(message.getCcAddresses()));
63: smm.setSubject(message.getSubject());
64: smm.setText(message.getMessage());
65: smm.setFrom(message.getFromAddress());
66:
67: try {
68: mailSender.send(smm);
69: } catch (MailException e) {
70: throw new InvalidAddressException(e);
71: }
72: }
73:
74: public void setMailSender(MailSender ms) {
75: mailSender = ms;
76: }
77:
78: /**
79: * Sets the batchMailingList attribute value.
80: * @param batchMailingList The batchMailingList to set.
81: */
82: public void setBatchMailingList(String batchMailingList) {
83: this .batchMailingList = batchMailingList;
84: }
85:
86: /**
87: * @see org.kuali.core.service.MailService#getBatchMailingList()
88: */
89: public String getBatchMailingList() {
90: return batchMailingList;
91: }
92: }
|