1 19 20 package com.lutris.airsent.business.email; 21 22 import com.lutris.util.Config; 23 import com.lutris.util.KeywordValueTable; 24 import com.lutris.airsent.business.AirSentBusinessException; 25 import com.lutris.airsent.spec.email.EmailManager; 26 27 34 public class EmailManagerImpl implements EmailManager { 35 protected final static String EMAIL_ACTIVE = "Active"; 36 protected final static String EMAIL_KEY = "Email"; 37 protected final static String MAIL_SERVER_NAME = "MailServer"; 38 protected final static String FROM_EMAIL_NAME = "AdminEmailName"; 39 protected final static String FROM_EMAIL_ADDRESS = "AdminEmailAddress"; 40 protected String mailServer = null; 41 protected String fromName = null; 42 protected String fromAddress = null; 43 protected boolean active = false; 44 45 50 public EmailManagerImpl() {} 51 52 60 public EmailManagerImpl(Config config) throws AirSentBusinessException { 61 try { 62 63 KeywordValueTable section = config.getSection(EMAIL_KEY); 65 66 mailServer = section.getString(MAIL_SERVER_NAME); 67 fromName = section.getString(FROM_EMAIL_NAME); 68 fromAddress = section.getString(FROM_EMAIL_ADDRESS); 69 active = Boolean.valueOf(section.getString(EMAIL_ACTIVE)).booleanValue(); 70 } catch (Exception ex) { 71 throw new AirSentBusinessException("Error sending mail:", ex); 72 } 73 } 74 75 76 90 public void send(String to, String toAddress, String subject, 91 String body, 92 String type) throws AirSentBusinessException { 93 try { 94 if(active) { 95 Email mail = new Email(mailServer); 96 mail.sendMail(fromName, fromAddress, toAddress, subject, type, 97 body); 98 } else { 99 System.out.println("Email is not active. Edit airSent.conf to activate."); 100 } 101 } catch (Exception ex) { 102 throw new AirSentBusinessException("Error sending mail:", ex); 103 } 104 } 105 106 } 107 108 | Popular Tags |