Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  1. public static void sendEmail(String address, Integer entityId, String messageKey, String attachmentFileName, String[] params) {
  2.        
  3.         String smptserver = com.sapienter.jbilling.common.Util.getSysProp("smtp_server") + ":" + com.sapienter.jbilling.common.Util.getSysProp("smtp_port");
  4.         String username = com.sapienter.jbilling.common.Util.getSysProp("smtp_username");
  5.         String password = com.sapienter.jbilling.common.Util.getSysProp("smtp_password");
  6.         String from = com.sapienter.jbilling.common.Util.getSysProp("email_from");
  7.         EntityBL entity = new EntityBL(entityId);
  8.         Locale locale = entity.getLocale();
  9.         ResourceBundle rBundle = ResourceBundle.getBundle("entityNotifications", locale);
  10.         String subject = rBundle.getString(messageKey + "_subject");
  11.         String message = rBundle.getString(messageKey + "_body");
  12.         if (params != null) {
  13.             for (int f = 0; f < params.length; f++) {
  14.                 message = message.replaceFirst("\\|X\\|", params[f]);
  15.             }
  16.         }
  17.         String statement = "echo \"" + message + "\"" +
  18.                     " | mailx -v -s \"" + subject + "\"" +
  19.                     " -S smtp=smtp://" + smptserver +
  20.                     " -S smtp-auth-user=" + username +
  21.                     " -S smtp-auth-password=" + password +
  22.                     " -S nss-config-dir=/home/capgemini/.mozilla/firefox/7cl9hq4v.default/" +
  23.                     " -S ssl-verify=ignore -S smtp-use-starttls" +
  24.                     " -S from=" + from +
  25.                     " -a " + attachmentFileName +
  26.                     " " + address;
  27.         File tempfile = getScript(statement);
  28.         LOG.debug("ALD: statement=[" + statement + "]");
  29.         try {
  30.             String command = "sh " + tempfile.getPath();
  31.             LOG.debug("ALD: executing command=[" + command + "]");
  32.             Process p = Runtime.getRuntime().exec(command);
  33.             p.waitFor();
  34.             BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
  35.             BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
  36.             tempfile.delete();
  37.            
  38.             String s = null;
  39.             // read the output from the command
  40.             System.out.println("Here is the standard output of the command:\n");
  41.             while ((s = stdInput.readLine()) != null) {
  42.                 System.out.println(s);
  43.             }
  44.              
  45.             // read any errors from the attempted command
  46.             System.out.println("Here is the standard error of the command (if any):\n");
  47.             while ((s = stdError.readLine()) != null) {
  48.                 System.out.println(s);
  49.             }
  50.         } catch (IOException e) {
  51.             // TODO Auto-generated catch block
  52.             e.printStackTrace();
  53.         } catch (InterruptedException e) {
  54.             // TODO Auto-generated catch block
  55.             e.printStackTrace();           
  56.         }
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement