/[projects]/miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/notification/MailNotifier.java
ViewVC logotype

Annotation of /miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/notification/MailNotifier.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1148 - (hide annotations) (download)
Fri Oct 1 11:40:30 2010 UTC (13 years, 8 months ago) by torben
Original Path: CircuitBreaker/src/dk/thoerup/circuitbreaker/notification/MailNotifier.java
File size: 1424 byte(s)
Support for async notifiers (and basic java notifier - needs debugging)
1 torben 1148 package dk.thoerup.circuitbreaker.notification;
2    
3     import java.util.Properties;
4    
5     import javax.mail.Message;
6     import javax.mail.Session;
7     import javax.mail.Transport;
8     import javax.mail.internet.InternetAddress;
9     import javax.mail.internet.MimeMessage;
10    
11     import java.util.logging.*;
12    
13     import dk.thoerup.circuitbreaker.CircuitBreaker;
14    
15     public class MailNotifier extends AsyncNotifier {
16    
17    
18     Logger logger = Logger.getLogger(MailNotifier.class.getName());
19    
20     private String recipient;
21     private String from;
22    
23     Properties props;
24    
25     public MailNotifier(CircuitBreaker cb, String from, String recipient, String mailhost) {
26     super(cb);
27    
28     this.from = from;
29     this.recipient = recipient;
30    
31     props = new Properties();
32     props.put("mail.smtp.host", mailhost);
33     }
34    
35     @Override
36     public void sendAsync(String breakerName, Event evnt) {
37     try {
38    
39     // create some properties and get the default Session
40     Session session = Session.getDefaultInstance(props, null);
41     session.setDebug(true);
42    
43    
44     // create a message
45    
46     MimeMessage msg = new MimeMessage(session);
47     msg.setFrom( new InternetAddress(from) );
48    
49     msg.setRecipient(Message.RecipientType.TO, new InternetAddress(recipient) );
50     msg.setSubject("Circuitbreaker " + breakerName + " : " + evnt.toString());
51     msg.setText("--");
52    
53     Transport.send(msg);
54     } catch (Exception e) {
55     logger.warning("Unable to send CircuitBreaker notification mail " + e );
56     }
57    
58    
59     }
60    
61     }

  ViewVC Help
Powered by ViewVC 1.1.20