1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
73
74
75 public void setBatchMailingList(String batchMailingList) {
76 this.batchMailingList = batchMailingList;
77 }
78
79
80
81
82 public String getBatchMailingList() {
83 return batchMailingList;
84 }
85
86
87
88
89 public String getIncidentMailingList() {
90 return this.incidentMailingList;
91 }
92
93
94
95
96 public void setIncidentMailingList(String incidentMailingList) {
97 this.incidentMailingList = incidentMailingList;
98 }
99
100 }