1 4 package com.nightlabs.rcp.exceptionhandler.wizard; 5 6 9 10 import java.util.Iterator ; 11 import java.util.Properties ; 12 import javax.mail.*; 13 import javax.mail.internet.InternetAddress ; 14 import javax.mail.internet.MimeMessage ; 15 16 import org.apache.log4j.Logger; 17 18 import com.nightlabs.config.Config; 19 20 public class ErrorReportSenderEMail implements ErrorReportSender 21 { 22 public static final Logger LOGGER = Logger.getLogger(ErrorReportSenderEMail.class); 23 24 public ErrorReportSenderEMail() 25 { 26 super(); 27 } 28 29 32 public void sendErrorReport(ErrorReport errorReport) 33 { 34 try { 35 ErrorReportEMailCfMod cfMod = (ErrorReportEMailCfMod) Config.sharedInstance().createConfigModule(ErrorReportEMailCfMod.class); 36 Properties props = new Properties (); 37 props.put("mail.host", cfMod.getSmtpHost()); 38 40 41 Session mailConnection = Session.getInstance(props, null); 42 Message msg = new MimeMessage (mailConnection); 43 Address mailFrom = new InternetAddress (cfMod.getMailFrom()); 44 46 msg.setText(errorReport.toString()); 48 msg.setFrom(mailFrom); 49 50 51 60 for(Iterator it2 = cfMod.getMailTo().iterator(); it2.hasNext();) 61 msg.addRecipient(Message.RecipientType.TO, new InternetAddress ((String )it2.next())); 62 63 64 65 msg.setSubject(errorReport.getThrownException().getClass().getName() + " " + errorReport.getCurrentTimeAsString()); 66 67 68 Transport.send(msg); 69 System.out.println("Message was sent!"); 70 } catch (Exception e) { 71 LOGGER.fatal("Sending error report by eMail failed.", e); 72 } 73 } 74 75 } 76 | Popular Tags |