public void sendNotificationMail(
      String toList,
      String ccList,
      String bccList,
      String emailSubject,
      String emailText,
      boolean isException,
      String attachmentpos)
      throws Exception {
    try {
      // In case of Exception email, Read the Property file to get To/CC/Sub from property file.
      if (isException) {
        PropertyFileReader propertyReader = PropertyFileReader.getInstance();
        toList = propertyReader.getStringProperty("errorMailTo");
        ccList = propertyReader.getStringProperty("errorMailCC");
        emailSubject = propertyReader.getStringProperty("errorMailSubject");
      }
      // bcc & attachmentPos is hardcoded NULL in case of exception email
      sendMail(toList, ccList, bccList, emailSubject, emailText, null);

      /*emailNotificationBean.setAllValues(toList, ccList, bccList, emailSubject, emailText);
      sendMail(toList, ccList, bccList, emailSubject, emailText, attachmentpos);
      /*NotificationCenterBean emailNotificationBean = new NotificationCenterBean();
      emailNotificationBean.setAllValues(toList, ccList, bccList, emailSubject, emailText);
      System.out.println(emailNotificationBean);
      notificationCenterService.saveNotification(emailNotificationBean);*/
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @org.junit.Test(expected = PropertyLoaderException.class)
  public void
      testLoadPropertiesFromBaseNameList_Calls_PropertyFileReader_And_Prevents_StackOverflow() {
    Stack<String> fileNameStack = new Stack<String>();
    when(propertyLoaderFactory.getEmptyProperties()).thenReturn(properties);
    when(propertyLoaderFactory.getEmptyFileNameStack()).thenReturn(fileNameStack);
    when(propertyLoaderFactory.getStringBuilder()).thenReturn(new StringBuilder());
    List<String> fileNames = Arrays.asList("file1.properties", "file2.properties");
    ArrayList<String> suffixes = new ArrayList<String>();
    when(propertySuffix.getSuffixes()).thenReturn(suffixes);
    when(propertyFileNameHelper.getFileNames(
            Matchers.anyCollection(), Matchers.anyCollection(), Matchers.anyString()))
        .thenReturn(fileNames);
    when(propertyLocation.getOpeners())
        .thenReturn(
            Arrays.<PropertyLoaderOpener>asList(propertyLoaderOpener1, propertyLoaderOpener2));
    when(propertyFileReader.tryToReadPropertiesFromFile(
            Matchers.anyString(), Matchers.anyString(), Matchers.any(PropertyLoaderOpener.class)))
        .thenReturn(properties);

    propertyLoader.load();

    verify(propertyFileReader)
        .tryToReadPropertiesFromFile("file1.properties", "ISO-8859-1", propertyLoaderOpener1);
    verify(propertyFileReader)
        .tryToReadPropertiesFromFile("file2.properties", "ISO-8859-1", propertyLoaderOpener1);
    verify(propertyFileReader)
        .tryToReadPropertiesFromFile("file1.properties", "ISO-8859-1", propertyLoaderOpener2);
    verify(propertyFileReader)
        .tryToReadPropertiesFromFile("file2.properties", "ISO-8859-1", propertyLoaderOpener2);
    verify(properties, times(4)).putAll(properties);
  }
  @Test
  public void getPropertiesFromFile_fileExist() {
    // given
    String fileName = "test_sts.properties";

    // when
    Properties result = PropertyFileReader.getPropertiesFromFile(fileName);

    // then
    assertNotNull(result);
  }
  @Test
  public void getPropertiesFromFile_fileDoesNotExist() {
    // given
    String fileName = "not_existing_file";

    // when
    Properties result = PropertyFileReader.getPropertiesFromFile(fileName);

    // then
    assertNull(result);
  }
  @Test
  public void getPropertiesFromFile_fileNameNull() {
    // given
    String fileName = null;

    // when
    Properties result = PropertyFileReader.getPropertiesFromFile(fileName);

    // then
    assertNull(result);
  }
 private void doInit() throws Exception {
   PropertyFileReader propertReader = PropertyFileReader.getInstance();
   emailId = propertReader.getStringProperty("errorMailFrom");
   password = propertReader.getStringProperty("errorMailPassword");
   protocol = propertReader.getStringProperty("mailProtocol");
   host = propertReader.getStringProperty("mailHost");
   smtpHost = propertReader.getStringProperty("mailSmtpHost");
   smtpPortNo = propertReader.getIntProperty("mailSmtpPortNo");
   props = System.getProperties();
   props.setProperty("mail.store.protocol", protocol);
   Authenticator auth = new EmailAuthentication(emailId, password);
   session = Session.getDefaultInstance(props, auth);
   store = session.getStore("pop3");
   store.connect(host, emailId, password);
   props.put("mail.smtp.port", smtpPortNo);
   props.put("mail.smtp.host", smtpHost);
   props.put("mail.smtp.auth", "true");
   props.put("mail.debug", "false");
   props.put("mail.smtp.ssl.enable", "false");
 }
// Decompiled by DJ v3.5.5.77 Copyright 2003 Atanas Neshkov  Date: 12/11/2006 9:50:27 AM
  private void sendMail(
      String to,
      String cc,
      String bcc,
      String subject,
      String msgContent,
      List<EmailAttachmentBean> emailAttachmentList)
      throws Exception {

    PropertyFileReader propertyFileReader = PropertyFileReader.getInstance();
    doInit();
    msgContent +=
        "<br/><br/><br/><br/> This is a system generated email, do not reply to this email id.";
    MimeMessage message = new MimeMessage(session);
    // Set From: header field of the header.
    message.setFrom(new InternetAddress(emailId));
    // Set To: header field of the header.
    message.addRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
    if (cc != null && cc.length() != 0)
      message.addRecipients(Message.RecipientType.CC, InternetAddress.parse(cc));

    if (bcc != null && bcc.length() != 0) {
      bcc = bcc.replaceAll(";", ",");
      message.addRecipients(Message.RecipientType.BCC, InternetAddress.parse(bcc));
    }
    // Set Subject: header field
    message.setSubject(subject);
    /* Start Here */
    // Create the message part
    MimeBodyPart messageBodyPart = new MimeBodyPart();
    // Fill the message
    messageBodyPart.setText(
        "<pre style='font-size:16px;font-family: Calibri'>" + msgContent + "</pre>", null, "html");
    // Create a multipar message
    Multipart multipart = new MimeMultipart();

    // please don't delete this code before deleting please let me know @Siva Sankar
    // this code is for sending email with attachment
    if (emailAttachmentList != null && !emailAttachmentList.isEmpty()) {
      for (EmailAttachmentBean emailAttachmentBean : emailAttachmentList) {
        MimeBodyPart attachmentPart = new MimeBodyPart();

        DataSource source =
            new ByteArrayDataSource(emailAttachmentBean.getFileContent(), "text/html");
        attachmentPart.setDataHandler(new DataHandler(source));
        attachmentPart.setFileName(emailAttachmentBean.getFileName());

        multipart.addBodyPart(attachmentPart);
      }
      /*if (attachmentpos != null && attachmentpos.contains("&&&&")) {
      	MimeBodyPart attachmentPart = new MimeBodyPart();
      	String[] strArray = attachmentpos.split("&&&&");
      	String attchFileContent = strArray[0];
      	String attchFileName = strArray[1].trim();
      	DataSource source = new FileDataSource(attchFileContent);
      	attachmentPart.setDataHandler(new DataHandler(source));
      	attachmentPart.setFileName(attchFileName);
      	multipart.addBodyPart(attachmentPart);
      }*/
    }
    // Set text message part
    multipart.addBodyPart(messageBodyPart);
    // Send the complete message parts
    message.setContent(multipart);
    // Send message
    Transport.send(message);
    /* End Here */

    System.out.println("Sent message successfully.... Sent to " + to);
  }