private void sendNotification(Admin admin, NotificationCreator notificationcreator, String username, String password, String dn, String subjectaltname, String email, int caid){ try { if(email== null) throw new Exception("Notification cannot be sent to user where email field is null"); javax.mail.Session mailSession = (javax.mail.Session) new InitialContext().lookup( "java:comp/env/mail/DefaultMail" ); javax.mail.Message msg = new MimeMessage( mailSession ); msg.setFrom( new InternetAddress( notificationcreator.getSender()) ); msg.setRecipients( javax.mail.Message.RecipientType.TO, InternetAddress.parse( email, false ) ); msg.setSubject( notificationcreator.getSubject() ); msg.setContent( notificationcreator.getMessage(username, password, dn, subjectaltname, email), "text/plain" ); msg.setHeader( "X-Mailer", "JavaMailer" ); msg.setSentDate( new java.util.Date() ); Transport.send( msg ); logsession.log(admin, caid, LogEntry.MODULE_RA, new java.util.Date(),username, null, LogEntry.EVENT_INFO_NOTIFICATION,"Notification to " + email + " sent successfully."); } catch ( Exception e ) { try{ logsession.log(admin, caid, LogEntry.MODULE_RA, new java.util.Date(),username, null, LogEntry.EVENT_ERROR_NOTIFICATION, "Error when sending notification to " + email ); }catch(Exception f){ throw new EJBException(f); } } }
private void sendNotification(Admin admin, EndEntityProfile profile, String username, String password, String dn, String subjectaltname, String email, int caid) { try { if (email == null) { throw new Exception("Notification cannot be sent to user where email field is null"); }  Session mailSession = getLocator().getMailSession(JNDINames.MAIL_SESSION); DNFieldExtractor dnfields = new DNFieldExtractor(dn, DNFieldExtractor.TYPE_SUBJECTDN); HashMap params = new HashMap(); params.put("USERNAME", username); params.put("PASSWORD", password); params.put("CN", dnfields.getField(DNFieldExtractor.CN, 0)); params.put("O", dnfields.getField(DNFieldExtractor.O, 0)); params.put("OU", dnfields.getField(DNFieldExtractor.OU, 0)); params.put("C", dnfields.getField(DNFieldExtractor.C, 0)); params.put("NL", System.getProperty("line.separator")); String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date()); params.put("DATE", date);  Message msg = new TemplateMimeMessage(params, mailSession); msg.setFrom(new InternetAddress(profile.getNotificationSender())); msg.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(email, false)); msg.setSubject(profile.getNotificationSubject()); msg.setContent(profile.getNotificationMessage(), "text/plain"); msg.setHeader("X-Mailer", "JavaMailer"); msg.setSentDate(new Date()); Transport.send(msg);  logsession.log(admin, caid, LogEntry.MODULE_RA, new java.util.Date(), username, null, LogEntry.EVENT_INFO_NOTIFICATION, "Notification to " + email + " sent successfully."); } catch (Exception e) { logsession.log(admin, caid, LogEntry.MODULE_RA, new java.util.Date(), username, null, LogEntry.EVENT_ERROR_NOTIFICATION, "Error when sending notification to " + email); throw new EJBException(e); } }
   private void sendNotification(Admin admin, NotificationCreator notificationcreator, String username, String password, String dn, String subjectaltname, String email, int caid){     try {       if(email== null)         throw new Exception("Notification cannot be sent to user where email field is null");       javax.mail.Session mailSession = (javax.mail.Session) new InitialContext().lookup( "java:comp/env/mail/DefaultMail" );       javax.mail.Message msg = new MimeMessage( mailSession );       msg.setFrom( new InternetAddress( notificationcreator.getSender()) );       msg.setRecipients( javax.mail.Message.RecipientType.TO, InternetAddress.parse( email, false ) );       msg.setSubject( notificationcreator.getSubject() );       msg.setContent( notificationcreator.getMessage(username, password, dn, subjectaltname, email), "text/plain" );       msg.setHeader( "X-Mailer", "JavaMailer" );       msg.setSentDate( new java.util.Date() );       Transport.send( msg );       logsession.log(admin, caid, LogEntry.MODULE_RA, new java.util.Date(),username, null, LogEntry.EVENT_INFO_NOTIFICATION,"Notification to " + email + " sent successfully.");     }     catch ( Exception e )     {       try{         logsession.log(admin, caid, LogEntry.MODULE_RA, new java.util.Date(),username, null, LogEntry.EVENT_ERROR_NOTIFICATION, "Error when sending notification to " + email );       }catch(Exception f){          throw new EJBException(f);       }     }   } // sendNotification