View Javadoc

1   /*
2    * Copyright (c) 2005 Your Corporation. All Rights Reserved.
3    */
4   package org.bejug.javacareers.jobs.service;
5   
6   import org.bejug.javacareers.common.exception.MailException;
7   import org.springframework.mail.SimpleMailMessage;
8   import org.springframework.mail.javamail.JavaMailSenderImpl;
9   
10  /***
11   * @author Bart Meyers (last modified by $Author: ge0ffrey $)
12   * @version $Revision: 1.1 $ $Date: 2005/08/26 07:58:31 $
13   *  
14   */
15  public class MailServiceImpl implements MailService {
16  
17      /***
18       * the message to send.
19       */
20      private SimpleMailMessage message = null;
21  
22      /***
23       * the mailSender provided by Spring.
24       */
25      private JavaMailSenderImpl mailSender = null;
26  
27      /***
28       * @return the mailsender we want.
29       */
30      public JavaMailSenderImpl getMailSender() {
31          return mailSender;
32      }
33  
34      /***
35       * @param mailSender
36       *            the mailsender to set.
37       */
38      public void setMailSender(JavaMailSenderImpl mailSender) {
39          this.mailSender = mailSender;
40      }
41  
42      /***
43       * @return the message we want.
44       */
45      public SimpleMailMessage getMessage() {
46          return message;
47      }
48  
49      /***
50       * @param message
51       *            the message to set.
52       */
53      public void setMessage(SimpleMailMessage message) {
54          this.message = message;
55      }
56  
57      /***
58       * {@inheritDoc}
59       */
60      public void sendNotificationMessage(String to, String cc, String bcc,
61              String from, String subject, String text) throws MailException {
62          try {
63              if (message != null) {
64                  if (to == null && cc == null && bcc == null) {
65                      throw new MailException("Sending a mail to nobody");
66                  }
67                  if (text == null) {
68                      throw new MailException("No content for your mail");
69                  }
70                  if (to != null) {
71                      message.setTo(to);
72                  }
73                  if (cc != null) {
74                      message.setCc(cc);
75                  }
76                  if (bcc != null) {                   
77                      message.setBcc(bcc);
78                  }
79                  message.setFrom(from);
80                  message.setSubject(subject);
81                  message.setText(text);
82                  getMailSender().send(message);
83              } else {
84                  throw new MailException(
85                          "No message available when sending a mail");
86              }
87          } catch (org.springframework.mail.MailException me) {
88              throw new MailException(me);
89          }
90      }
91  }
92  /***
93   * $Log: MailServiceImpl.java,v $
94   * Revision 1.1  2005/08/26 07:58:31  ge0ffrey
95   * split up the sources in service, serviceimpl and webclient
96   *
97   * Revision 1.2  2005/06/09 08:18:52  bejug_cc
98   * Fix initial import
99   *
100  * Revision 1.5  2005/05/22 16:42:54  sja
101  * Removed mail notification to multiple users.
102  *
103  * Revision 1.4  2005/05/18 13:48:34  bme
104  * corrected a little error ( & replaced by &&)
105  *
106  * Revision 1.3  2005/05/18 10:21:23  bme
107  * updated
108  * Revision 1.2 2005/05/17 14:22:17 ssc
109  * checkstyle
110  * 
111  * Revision 1.1 2005/05/13 14:07:50 bme mailservice first draft
112  *  
113  */