List of usage examples for javax.mail MessagingException printStackTrace
public void printStackTrace()
From source file:com.krawler.hrms.hrmsHandler.java
public static JSONObject createapplicantFunction(Session session, HttpServletRequest request) throws ServiceException, JSONException, ParseException, SessionExpiredException, UnsupportedEncodingException, NoSuchAlgorithmException, MessagingException { JSONObject jobj = new JSONObject(); List list = null;//ww w . j a va 2s. c om String SELECT_USER_INFO; Jobapplicant jobapp; JSONArray jarr; SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); try { String pwd = request.getParameter("p"); String cmp = AuthHandler.getCompanyid(request); if (StringUtil.isNullOrEmpty(request.getParameter("update"))) { SELECT_USER_INFO = "from Jobapplicant where username=? and company.companyID=? "; list = HibernateUtil.executeQuery(session, SELECT_USER_INFO, new Object[] { request.getParameter("u"), cmp }); if (list.size() == 0) { jobapp = new Jobapplicant(); String id = UUID.randomUUID().toString(); Company cmpid = (Company) session.load(Company.class, cmp); jobapp.setApplicantid(id); jobapp.setFirstname(request.getParameter("fname")); jobapp.setLastname(request.getParameter("lname")); jobapp.setEmail(request.getParameter("e")); jobapp.setAddress1(request.getParameter("addr")); jobapp.setContactno(request.getParameter("contact")); jobapp.setUsername(request.getParameter("u")); jobapp.setPassword(AuthHandler.getSHA1(pwd)); jobapp.setStatus(0); jobapp.setCompany(cmpid); session.save(jobapp); String uri = URLUtil.getPageURL(request, Links.loginpagewthFull, cmpid.getSubDomain()) + "applicantLogin.html"; String pmsg = String.format(KWLErrorMsgs.msgMailInvite, jobapp.getFirstname(), "Demo", jobapp.getUsername(), pwd, uri, "Demo"); String htmlmsg = String.format(HrmsMsgs.msgMailInviteUsernamePassword, jobapp.getFirstname(), AuthHandler.getFullName(session, AuthHandler.getUserid(request)), AuthHandler.getCompanyName(request), jobapp.getUsername(), pwd, uri, uri, ""); try { SendMailHandler.postMail(new String[] { jobapp.getEmail() }, "[Deskera] Welcome to Deskera HRMS", htmlmsg, pmsg, "admin.hrms@mailinator.com"); } catch (MessagingException e) { e.printStackTrace(); } jobj.put("msg", "Applicant created successfully"); //@@ProfileHandler.insertAuditLog(session, AuditAction.CREATE_APPLICANT, "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has created new applicant " + jobapp.getFirstname() + " " + jobapp.getLastname(),request); } else { jobj.put("msg", "User name already exist"); } } else { SELECT_USER_INFO = "from Jobapplicant where applicantid=?"; list = HibernateUtil.executeQuery(session, SELECT_USER_INFO, new Object[] { request.getParameter("profileid") }); if (!list.isEmpty()) { String jsondata1 = request.getParameter("jsondata1"); String jsondata2 = request.getParameter("jsondata2"); String jsondata3 = request.getParameter("jsondata3"); String jsondata4 = request.getParameter("jsondata4"); String jsondata5 = request.getParameter("jsondata5"); jobapp = (Jobapplicant) session.load(Jobapplicant.class, request.getParameter("profileid")); if (jsondata1.length() > 0) { jarr = new JSONArray("[" + jsondata1 + "]"); for (int i = 0; i < jarr.length(); i++) { jobj = jarr.getJSONObject(i); jobapp.setTitle(jobj.getString("title")); jobapp.setFirstname(jobj.getString("firstname")); jobapp.setLastname(jobj.getString("lastname")); jobapp.setEmail(jobj.getString("email")); jobapp.setOtheremail(jobj.getString("otheremail")); jobapp.setBirthdate((Date) fmt.parse(jobj.getString("birthdate"))); } } if (jsondata2.length() > 0) { jarr = new JSONArray("[" + jsondata2 + "]"); for (int i = 0; i < jarr.length(); i++) { jobj = jarr.getJSONObject(i); jobapp.setContactno(jobj.getString("contactno")); jobapp.setMobileno(jobj.getString("mobileno")); jobapp.setCity(jobj.getString("city")); jobapp.setState(jobj.getString("state")); jobapp.setCountryid( (MasterData) session.load(MasterData.class, jobj.getString("country"))); jobapp.setAddress1(jobj.getString("address1")); jobapp.setAddress2(jobj.getString("address2")); } } if (jsondata3.length() > 0) { jarr = new JSONArray("[" + jsondata3 + "]"); for (int i = 0; i < jarr.length(); i++) { jobj = jarr.getJSONObject(i); if (StringUtil.isNullOrEmpty(jobj.getString("graddegree")) == false) { jobapp.setGraddegree(jobj.getString("graddegree")); } if (StringUtil.isNullOrEmpty(jobj.getString("gradspecilization")) == false) { jobapp.setGradspecialization(jobj.getString("gradspecilization")); } if (StringUtil.isNullOrEmpty(jobj.getString("gradcollege")) == false) { jobapp.setGradcollege(jobj.getString("gradcollege")); } if (StringUtil.isNullOrEmpty(jobj.getString("graduniversity")) == false) { jobapp.setGraduniversity(jobj.getString("graduniversity")); } if (StringUtil.isNullOrEmpty(jobj.getString("gradepercent")) == false) { jobapp.setGradpercent(jobj.getString("gradepercent")); } if (StringUtil.isNullOrEmpty(jobj.getString("gradpassdate")) == false) { jobapp.setGradpassdate((Date) fmt.parse(jobj.getString("gradpassdate"))); } if (StringUtil.isNullOrEmpty(jobj.getString("pgqualification")) == false) { jobapp.setPgqualification(jobj.getString("pgqualification")); } if (StringUtil.isNullOrEmpty(jobj.getString("pgspecialization")) == false) { jobapp.setPgspecialization(jobj.getString("pgspecialization")); } if (StringUtil.isNullOrEmpty(jobj.getString("pgcollege")) == false) { jobapp.setPgcollege(jobj.getString("pgcollege")); } if (StringUtil.isNullOrEmpty(jobj.getString("pguniversity")) == false) { jobapp.setPguniversity(jobj.getString("pguniversity")); } if (StringUtil.isNullOrEmpty(jobj.getString("pgpercent")) == false) { jobapp.setPgpercent(jobj.getString("pgpercent")); } if (StringUtil.isNullOrEmpty(jobj.getString("pgpassdate")) == false) { jobapp.setPgpassdate((Date) fmt.parse(jobj.getString("pgpassdate"))); } if (StringUtil.isNullOrEmpty(jobj.getString("othername")) == false) { jobapp.setOthername(jobj.getString("othername")); } if (StringUtil.isNullOrEmpty(jobj.getString("otherqualification")) == false) { jobapp.setOtherqualification(jobj.getString("otherqualification")); } if (StringUtil.isNullOrEmpty(jobj.getString("otherpercent")) == false) { jobapp.setOtherpercent(jobj.getString("otherpercent")); } if (StringUtil.isNullOrEmpty(jobj.getString("otherdetails")) == false) { jobapp.setOtherdetails(jobj.getString("otherdetails")); } if (StringUtil.isNullOrEmpty(jobj.getString("otherpassdate")) == false) { jobapp.setOtherpassdate((Date) fmt.parse(jobj.getString("otherpassdate"))); } } } if (jsondata4.length() > 0) { jarr = new JSONArray("[" + jsondata4 + "]"); for (int i = 0; i < jarr.length(); i++) { jobj = jarr.getJSONObject(i); if (jobj.getString("experiencemonth").equals("")) { jobapp.setExperiencemonth(0); } else { jobapp.setExperiencemonth(Integer.parseInt(jobj.getString("experiencemonth"))); } if (StringUtil.isNullOrEmpty(jobj.getString("experienceyear")) == false) { jobapp.setExperienceyear(Integer.parseInt(jobj.getString("experienceyear"))); } if (StringUtil.isNullOrEmpty(jobj.getString("functionalexpertise")) == false) { jobapp.setFunctionalexpertise(jobj.getString("functionalexpertise")); } if (StringUtil.isNullOrEmpty(jobj.getString("currentindustry")) == false) { jobapp.setCurrentindustry(jobj.getString("currentindustry")); } if (StringUtil.isNullOrEmpty(jobj.getString("currentorganization")) == false) { jobapp.setCurrentorganization(jobj.getString("currentorganization")); } if (StringUtil.isNullOrEmpty(jobj.getString("currentdesignation")) == false) { jobapp.setCurrentdesignation(jobj.getString("currentdesignation")); } if (StringUtil.isNullOrEmpty(jobj.getString("grosssalary")) == false) { jobapp.setGrosssalary(Integer.parseInt(jobj.getString("grosssalary"))); } jobapp.setExpectedsalary(Integer.parseInt(jobj.getString("expectedsalary"))); } } if (jsondata5.length() > 0) { jarr = new JSONArray("[" + jsondata5 + "]"); for (int i = 0; i < jarr.length(); i++) { jobj = jarr.getJSONObject(i); jobapp.setKeyskills(jobj.getString("keyskills")); if (StringUtil.isNullOrEmpty(jobj.getString("category")) == false) { jobapp.setCategory(jobj.getString("category")); } if (StringUtil.isNullOrEmpty(jobj.getString("filepath")) == false) { jobapp.setFilepath(jobj.getString("filepath")); } if (StringUtil.isNullOrEmpty(jobj.getString("companyrelative")) == false) { jobapp.setCompanyrelative(jobj.getString("companyrelative")); } if (StringUtil.isNullOrEmpty(jobj.getString("appearedbefore")) == false) { jobapp.setAppearedbefore(jobj.getString("appearedbefore")); if (jobj.getString("appearedbefore").equalsIgnoreCase("yes")) { if (StringUtil.isNullOrEmpty(jobj.getString("interviewplace")) == false) { jobapp.setInterviewplace(jobj.getString("interviewplace")); } if (StringUtil.isNullOrEmpty(jobj.getString("interviewdate")) == false) { jobapp.setInterviewdate((Date) fmt.parse(jobj.getString("interviewdate"))); } if (StringUtil.isNullOrEmpty(jobj.getString("interviewposition")) == false) { jobapp.setInterviewposition((MasterData) session.load(MasterData.class, jobj.getString("interviewposition"))); } } } jobapp.setInterviewlocation(jobj.getString("interviewlocation")); session.update(jobapp); } } } jobj.put("msg", "Applicant updated successfully."); } } catch (SessionExpiredException se) { throw new SessionExpiredException("createapplicantFunction", se.COMPANYID_NULL); } catch (ServiceException ex) { throw ServiceException.FAILURE("createapplicantFunction", ex); } catch (JSONException ex) { throw new JSONException("createapplicantFunction"); // } catch (NoSuchAlgorithmException ex) { // throw new JSONException("createapplicantFunction"); } catch (ParseException ex) { throw new JSONException("createapplicantFunction"); // } catch (UnsupportedEncodingException ex) { // throw new JSONException("createapplicantFunction"); } finally { } return jobj; }
From source file:fr.gouv.culture.vitam.eml.EmlExtract.java
private static final String addSubIdentities(Element identification, BodyPart bp, InputStream inputStream, VitamArgument argument, ConfigLoader config) { Element newElt = XmlDom.factory.createElement(EMAIL_FIELDS.subidentity.name); String filename = null;/*from w ww . j av a2 s. c om*/ String result = ""; try { filename = bp.getFileName(); filename = StringUtils.toFileName(filename); if (filename != null) { Element elt = XmlDom.factory.createElement(EMAIL_FIELDS.filename.name); elt.setText(filename); newElt.add(elt); } else { filename = "eml.eml"; } } catch (MessagingException e) { } try { int size = bp.getSize(); if (size > 0) { Element elt = XmlDom.factory.createElement(EMAIL_FIELDS.attSize.name); elt.setText(Integer.toString(size)); newElt.add(elt); } } catch (MessagingException e) { } try { String description = bp.getDescription(); if (description != null) { Element elt = XmlDom.factory.createElement(EMAIL_FIELDS.description.name); elt.setText(description); newElt.add(elt); } } catch (MessagingException e) { } try { String disposition = bp.getDisposition(); if (disposition != null) { Element elt = XmlDom.factory.createElement(EMAIL_FIELDS.disposition.name); elt.setText(disposition); newElt.add(elt); } } catch (MessagingException e) { } File filetemp = null; FileOutputStream outputStream = null; try { // Force out to analysis if (config.extractFile) { filetemp = new File(argument.currentOutputDir, filename); } else { filetemp = File.createTempFile(StaticValues.PREFIX_TEMPFILE, filename); } byte[] buffer = new byte[8192]; int read = 0; outputStream = new FileOutputStream(filetemp); while ((read = inputStream.read(buffer)) >= 0) { outputStream.write(buffer, 0, read); } outputStream.close(); outputStream = null; } catch (IOException e1) { if (filetemp != null && !config.extractFile) { filetemp.delete(); } if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { } } String status = "Error during access to attachment"; newElt.addAttribute(EMAIL_FIELDS.status.name, status); identification.add(newElt); return ""; } try { Commands.addFormatIdentification(newElt, filename, filetemp, config, argument); if (argument.extractKeyword) { // get back keyword in the main list Element keyw = (Element) newElt.selectSingleNode(EMAIL_FIELDS.keywords.name); if (keyw != null) { StringBuilder builder = new StringBuilder(); @SuppressWarnings("unchecked") List<Element> elts = (List<Element>) keyw.selectNodes(EMAIL_FIELDS.keywordRank.name); for (Element elt : elts) { String value = elt.attributeValue(EMAIL_FIELDS.keywordOccur.name); int occur = Integer.parseInt(value) / 2 + 1; @SuppressWarnings("unchecked") List<Element> words = (List<Element>) elt.selectNodes(EMAIL_FIELDS.keywordWord.name); for (Element eword : words) { String word = eword.attributeValue(EMAIL_FIELDS.keywordValue.name) + " "; for (int i = 0; i < occur; i++) { builder.append(word); } } } result = builder.toString().trim(); } } } catch (Exception e) { String status = "Error during identification"; e.printStackTrace(); config.addRankId(newElt); newElt.addAttribute(EMAIL_FIELDS.status.name, status); } if (filetemp != null && !config.extractFile) { filetemp.delete(); } identification.add(newElt); return result; }
From source file:com.krawler.spring.hrms.rec.job.hrmsRecJobController.java
public ModelAndView addRecruitersFunction(HttpServletRequest request, HttpServletResponse response) { //Status 0=pending,1=accepted,2=rejected,3=Not sent List tabledata = null;//from w ww.java 2 s. c o m String hql = null; Recruiter pos = null; JSONObject jobj = new JSONObject(); JSONObject jobj1 = new JSONObject(); KwlReturnObject result = null; //Create transaction DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("JE_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); TransactionStatus status = txnManager.getTransaction(def); try { HashMap<String, Object> requestParams = new HashMap<String, Object>(); ArrayList filter_names = new ArrayList(), filter_values = new ArrayList(); String[] recids = null; String auditmsg = ""; Company cmpid = (Company) kwlCommonTablesDAOObj.getObject("com.krawler.common.admin.Company", sessionHandlerImplObj.getCompanyid(request)); User u = (User) kwlCommonTablesDAOObj.getObject("com.krawler.common.admin.User", sessionHandlerImplObj.getUserid(request)); if (StringUtil.isNullOrEmpty(request.getParameter("delrec"))) { recids = request.getParameterValues("jobids"); for (int i = 0; i < recids.length; i++) { requestParams.clear(); filter_names.clear(); filter_values.clear(); filter_names.add("recruit.userID"); filter_values.add(recids[i]); requestParams.put("filter_names", filter_names); requestParams.put("filter_values", filter_values); result = hrmsRecJobDAOObj.getRecruiter(requestParams); tabledata = result.getEntityList(); requestParams.clear(); if (!tabledata.isEmpty()) { pos = (Recruiter) tabledata.get(0); requestParams.put("Rid", pos.getRid()); requestParams.put("Delflag", 0); auditmsg = "User " + profileHandlerDAOObj.getUserFullName(sessionHandlerImplObj.getUserid(request)) + " has set " + StringUtil.getFullName(pos.getRecruit()) + " as interviewer"; } else { User md = (User) kwlCommonTablesDAOObj.getObject("com.krawler.common.admin.User", recids[i]); requestParams.put("Delflag", 0); //requestParams.put("Recruit",md); requestParams.put("Recruit", recids[i]); auditmsg = "User " + profileHandlerDAOObj.getUserFullName(sessionHandlerImplObj.getUserid(request)) + " has set " + StringUtil.getFullName(md) + " as interviewer"; } result = hrmsRecJobDAOObj.setRecruiters(requestParams); if (result.isSuccessFlag()) { auditTrailDAOObj.insertAuditLog(AuditAction.SET_AS_INTERVIEWER, auditmsg, request, "0"); } } } else { String[] delrecids = request.getParameterValues("appid"); for (int i = 0; i < delrecids.length; i++) { requestParams.clear(); filter_names.clear(); filter_values.clear(); filter_names.add("recruit.userID"); filter_values.add(delrecids[i]); requestParams.put("filter_names", filter_names); requestParams.put("filter_values", filter_values); result = hrmsRecJobDAOObj.getRecruiter(requestParams); tabledata = result.getEntityList(); requestParams.clear(); if (!tabledata.isEmpty()) { pos = (Recruiter) tabledata.get(0); requestParams.put("Rid", pos.getRid()); requestParams.put("Delflag", 3); auditmsg = "User " + StringUtil.getFullName(pos.getRecruit()) + " has been unassigned as interviewer by " + profileHandlerDAOObj.getUserFullName(sessionHandlerImplObj.getUserid(request)); } result = hrmsRecJobDAOObj.setRecruiters(requestParams); if (result.isSuccessFlag()) { auditTrailDAOObj.insertAuditLog(AuditAction.SET_AS_INTERVIEWER, auditmsg, request, "0"); } } } if (StringUtil.isNullOrEmpty(request.getParameter("delrec"))) { for (int i = 0; i < recids.length; i++) { User r = (User) kwlCommonTablesDAOObj.getObject("com.krawler.common.admin.User", recids[i]); Useraccount ua = (Useraccount) kwlCommonTablesDAOObj .getObject("com.krawler.common.admin.Useraccount", r.getUserID()); String fullname = StringUtil.getFullName(r); String uri = URLUtil.getPageURL(request, Links.loginpagewthFull, cmpid.getSubDomain()) + "jspfiles/Confirmation.jsp?c=" + cmpid.getCompanyID() + "&u=" + r.getUserID() + "&acpt="; String pmsg = String.format(HrmsMsgs.interviewerSelectionpln, fullname); String htmlmsg = String.format(HrmsMsgs.interviewerSelectionHTML, fullname, uri + "1", uri + "0", StringUtil.getFullName(u), cmpid.getCompanyName()); try { SendMailHandler.postMail(new String[] { r.getEmailID() }, HrmsMsgs.interviewerSubject, htmlmsg, pmsg, u.getEmailID()); } catch (MessagingException e) { e.printStackTrace(); } } } jobj.put("success", true); jobj1.put("data", jobj.toString()); jobj1.put("valid", true); txnManager.commit(status); } catch (Exception e) { e.printStackTrace(); txnManager.rollback(status); } return new ModelAndView("jsonView", "model", jobj1.toString()); }
From source file:com.krawler.spring.hrms.rec.job.hrmsRecJobController.java
public ModelAndView scheduleinterview(HttpServletRequest request, HttpServletResponse response) { Date date1;/* w w w .jav a 2 s . c o m*/ DateFormat formatter; JSONObject jobj = new JSONObject(); String interviewdate = ""; //boolean reflag=false; String htmlmsg = ""; String pmsg = ""; String interviewsub = ""; KwlReturnObject result = null, recruitresult = null; //Create transaction DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("JE_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); TransactionStatus status = txnManager.getTransaction(def); try { HashMap<String, Object> requestParams = new HashMap<String, Object>(); String interviewtime = request.getParameter("interviewtime"); String location = request.getParameter("interviewplace"); formatter = new SimpleDateFormat("MM/dd/yyyy"); // Company cmp=(Company) session.get(Company.class,AuthHandler.getCompanyid(request)); requestParams.put("companyid", sessionHandlerImplObj.getCompanyid(request)); result = profileHandlerDAOObj.getCompanyid(requestParams); Company cmp = null; if (StringUtil.checkResultobjList(result)) { cmp = (Company) result.getEntityList().get(0); } date1 = (Date) formatter.parse(request.getParameter("interviewdt")); //interviewdate=(AuthHandler.getUserDateFormatter(request,session).format(date1)); requestParams.clear(); requestParams.put("request", request); interviewdate = request.getParameter("interviewdt"); Allapplications allapl = null; String[] ids = request.getParameterValues("ids"); String[] emailids = new String[ids.length]; String[] Resumeids = new String[ids.length]; String[] jobs = new String[ids.length]; String[] applicant = new String[ids.length]; Boolean[] reflag = new Boolean[ids.length]; for (int i = 0; i < ids.length; i++) { requestParams.clear(); requestParams.put("id", ids[i]); requestParams.put("primary", true); result = hrmsRecJobDAOObj.getPositionstatus(requestParams); allapl = (Allapplications) result.getEntityList().get(0); if (allapl.getStatus().equalsIgnoreCase("In Process")) { reflag[i] = true; } else { reflag[i] = false; } requestParams.clear(); requestParams.put("id", ids[i]); requestParams.put("status", "In Process"); requestParams.put("interviewdate", date1); requestParams.put("interviewtime", interviewtime); requestParams.put("interviewplace", location); requestParams.put("contactperson", request.getParameter("contactperson")); requestParams.put("interviewcomment", request.getParameter("interviewcomment")); //set rid to recruiter table and remove recruiter column from allapp requestParams.put("recruiter", request.getParameter("rid")); result = hrmsRecJobDAOObj.addAllapplications(requestParams); if (StringUtil.checkResultobjList(result)) { allapl = (Allapplications) result.getEntityList().get(0); requestParams.clear(); String[] Recruiterids = request.getParameter("rid").split(","); requestParams.put("Allapplication", allapl.getId()); boolean success = hrmsRecJobDAOObj.deleteRecruiters(requestParams); requestParams.put("Delflag", 0); for (int j = 0; j < Recruiterids.length && success; j++) { requestParams.put("Recruit", Recruiterids[j]); recruitresult = hrmsRecJobDAOObj.setRecruiters(requestParams); } } jobs[i] = (allapl.getPosition().getPosition().getValue() + " [" + allapl.getPosition().getJobid() + "] "); if (Integer.parseInt(request.getParameter("employeetype")) == 1) { emailids[i] = allapl.getEmployee().getEmailID(); applicant[i] = (allapl.getEmployee().getFirstName() + " " + allapl.getEmployee().getLastName()); } else { emailids[i] = allapl.getConfigjobapplicant().getCol3(); applicant[i] = (allapl.getConfigjobapplicant().getCol1() + " " + allapl.getConfigjobapplicant().getCol2()); Resumeids[i] = allapl.getConfigjobapplicant().getCol5(); } String usrnm; if (allapl.getEmployee() != null) { usrnm = StringUtil.getFullName(allapl.getEmployee()); } else { usrnm = allapl.getConfigjobapplicant().getCol1() + " " + allapl.getConfigjobapplicant().getCol2(); } //@@ProfileHandler.insertAuditLog(session, AuditAction.INTERVIEW_SCHEDULED, "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has scheduled interview for " + usrnm + " on "+ interviewdate + " at " + allapl.getInterviewplace(),request); } // User usr=(User) session.get(User.class,AuthHandler.getUserid(request)); Useraccount ua = (Useraccount) kwlCommonTablesDAOObj.getObject("com.krawler.common.admin.Useraccount", sessionHandlerImplObj.getUserid(request)); User usr = ua.getUser(); if (!StringUtil.isNullOrEmpty(request.getParameter("mail"))) { for (int j = 0; j < emailids.length; j++) { if (reflag[j]) { pmsg = String.format(HrmsMsgs.rescheduleinterviewPlnmsg, applicant[j], jobs[j], cmp.getCompanyName(), interviewdate, interviewtime, location, usr.getContactNumber(), usr.getEmailID(), usr.getFirstName() + " " + usr.getLastName(), ua.getDesignationid() != null ? ua.getDesignationid().getValue() : " ", cmp.getCompanyName()); htmlmsg = String.format(HrmsMsgs.rescheduleinterviewHTMLmsg, applicant[j], jobs[j], cmp.getCompanyName(), interviewdate, interviewtime, location, usr.getContactNumber(), usr.getEmailID(), usr.getFirstName() + " " + usr.getLastName(), ua.getDesignationid() != null ? ua.getDesignationid().getValue() : " ", cmp.getCompanyName()); interviewsub = String.format(HrmsMsgs.rescheduleinterviewSubject, allapl.getPosition().getJobid(), allapl.getPosition().getPosition().getValue(), cmp.getCompanyName()); try { SendMailHandler.postMail(new String[] { emailids[j] }, interviewsub, htmlmsg, pmsg, usr.getEmailID()); } catch (MessagingException e) { e.printStackTrace(); } } else { pmsg = String.format(HrmsMsgs.interviewPlnmsg, jobs[j], interviewdate, interviewtime, location); htmlmsg = String.format(HrmsMsgs.interviewHTMLmsg, applicant[j], jobs[j], cmp.getCompanyName(), interviewdate, interviewtime, location, usr.getContactNumber(), usr.getEmailID(), usr.getFirstName() + " " + usr.getLastName(), ua.getDesignationid() != null ? ua.getDesignationid().getValue() : " ", cmp.getCompanyName()); interviewsub = String.format(HrmsMsgs.interviewSubject, allapl.getPosition().getJobid(), allapl.getPosition().getPosition().getValue(), cmp.getCompanyName()); try { SendMailHandler.postMail(new String[] { emailids[j] }, interviewsub, htmlmsg, pmsg, usr.getEmailID()); } catch (MessagingException e) { e.printStackTrace(); } } ArrayList params = new ArrayList(); params.add(allapl.getId()); ArrayList filter_names = new ArrayList(); filter_names.add("allapplication.id"); requestParams.clear(); requestParams.put("filter_names", filter_names); requestParams.put("filter_values", params); recruitresult = hrmsRecJobDAOObj.getRecruiters(requestParams); if (StringUtil.checkResultobjList(recruitresult)) { List recruiterlist = recruitresult.getEntityList(); for (int k = 0; k < recruiterlist.size(); k++) { Recruiter r = (Recruiter) recruiterlist.get(k); String interviewer = r.getRecruit().getFirstName() + " " + r.getRecruit().getLastName(); String intpmsg = String.format(HrmsMsgs.interviewinvitePlnmsg, interviewer, jobs[j], interviewdate, interviewtime, location); String inthtmlmsg = String.format(HrmsMsgs.interviewinviteHTMLmsg, interviewer, jobs[j], interviewdate, interviewtime, location, usr.getFirstName() + " " + usr.getLastName(), ua.getDesignationid() != null ? ua.getDesignationid().getValue() : " ", cmp.getCompanyName()); String interviewinvitesub = String.format(HrmsMsgs.interviewinviteSubject, allapl.getPosition().getJobid(), allapl.getPosition().getPosition().getValue(), cmp.getCompanyName()); if (StringUtil.isNullOrEmpty(Resumeids[j])) { try { SendMailHandler.postMail(new String[] { r.getRecruit().getEmailID() }, interviewinvitesub, inthtmlmsg, intpmsg, usr.getEmailID()); } catch (MessagingException e) { e.printStackTrace(); } } else { hrmsDocumentController hdc = new hrmsDocumentController(); KwlReturnObject kmsg = hrmsExtApplDocsDAOObj.downloadDocument(Resumeids[j]); HashMap ht = hdc.getDocInfo(kmsg, storageHandlerImplObj); try { if (ht != null && ht.containsKey("filename")) { SendMailHandler.postMail(new String[] { r.getRecruit().getEmailID() }, interviewinvitesub, inthtmlmsg, intpmsg, usr.getEmailID(), new String[] { (String) ht.get("attachment"), (String) ht.get("filename") }); } else { SendMailHandler.postMail(new String[] { r.getRecruit().getEmailID() }, interviewinvitesub, inthtmlmsg, intpmsg, usr.getEmailID()); } } catch (MessagingException e) { e.printStackTrace(); } } } } } } if (result.isSuccessFlag()) { String interviewersname = ""; String delimiter = ","; String[] temp = request.getParameter("rid").split(delimiter); for (int i = 0; i < temp.length; i++) { interviewersname += profileHandlerDAOObj.getUserFullName(temp[i]); if (temp.length > i + 1) interviewersname += ", "; } for (int i = 0; i < ids.length; i++) auditTrailDAOObj.insertAuditLog(AuditAction.INTERVIEW_SCHEDULED, "User " + profileHandlerDAOObj.getUserFullName(sessionHandlerImplObj.getUserid(request)) + " has scheduled interview for applicant " + request.getParameterValues("cname")[i] + ". Interviewers are " + interviewersname, request, "0"); } jobj.put("success", "true"); txnManager.commit(status); } catch (Exception ex) { ex.printStackTrace(); txnManager.rollback(status); } finally { return new ModelAndView("jsonView", "model", ""); } }
From source file:library.Form_Library.java
License:asdf
public void sendFromGMail(String from, String pass, String to, String subject, String body) { this.taBaoCao.append("Sent to " + to + " successfully.\n"); Properties props = System.getProperties(); String host = "smtp.gmail.com"; props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", host); props.put("mail.smtp.user", from); props.put("mail.smtp.password", pass); props.put("mail.smtp.port", "587"); props.put("mail.smtp.auth", "true"); Session session = Session.getDefaultInstance(props); MimeMessage message = new MimeMessage(session); try {//from w w w . ja v a 2s.c om message.setFrom(new InternetAddress(from)); InternetAddress toAddress = new InternetAddress(); // To get the array of addresses // for( int i = 0; i < to.length; i++ ) { toAddress = new InternetAddress(to); // } // for( int i = 0; i < toAddress.length; i++) { message.addRecipient(Message.RecipientType.TO, toAddress); // } message.setSubject(subject); message.setText(body); Transport transport = session.getTransport("smtp"); transport.connect(host, from, pass); transport.sendMessage(message, message.getAllRecipients()); System.out.print("Successfully Sent" + "\n"); transport.close(); } catch (AddressException ae) { ae.printStackTrace(); } catch (MessagingException me) { me.printStackTrace(); } }
From source file:fr.gouv.culture.vitam.eml.EmlExtract.java
public static String extractInfoMessage(MimeMessage message, Element root, VitamArgument argument, ConfigLoader config) {/* w w w . j ava2 s . co m*/ File oldDir = argument.currentOutputDir; if (argument.currentOutputDir == null) { if (config.outputDir != null) { argument.currentOutputDir = new File(config.outputDir); } } Element keywords = XmlDom.factory.createElement(EMAIL_FIELDS.keywords.name); Element metadata = XmlDom.factory.createElement(EMAIL_FIELDS.metadata.name); String skey = ""; String id = config.addRankId(root); Address[] from = null; Element sub2 = null; try { from = message.getFrom(); } catch (MessagingException e1) { String[] partialResult; try { partialResult = message.getHeader("From"); if (partialResult != null && partialResult.length > 0) { sub2 = XmlDom.factory.createElement(EMAIL_FIELDS.from.name); Element add = XmlDom.factory.createElement(EMAIL_FIELDS.fromUnit.name); add.setText(partialResult[0]); sub2.add(add); } } catch (MessagingException e) { } } Address sender = null; try { sender = message.getSender(); } catch (MessagingException e1) { String[] partialResult; try { partialResult = message.getHeader("Sender"); if (partialResult != null && partialResult.length > 0) { if (sub2 == null) { sub2 = XmlDom.factory.createElement(EMAIL_FIELDS.from.name); Element add = XmlDom.factory.createElement(EMAIL_FIELDS.fromUnit.name); add.setText(partialResult[0]); sub2.add(add); } } } catch (MessagingException e) { } } if (from != null && from.length > 0) { String value0 = null; Element sub = (sub2 != null ? sub2 : XmlDom.factory.createElement(EMAIL_FIELDS.from.name)); if (sender != null) { value0 = addAddress(sub, EMAIL_FIELDS.fromUnit.name, sender, null); } for (Address address : from) { addAddress(sub, EMAIL_FIELDS.fromUnit.name, address, value0); } metadata.add(sub); } else if (sender != null) { Element sub = (sub2 != null ? sub2 : XmlDom.factory.createElement(EMAIL_FIELDS.from.name)); addAddress(sub, EMAIL_FIELDS.fromUnit.name, sender, null); metadata.add(sub); } else { if (sub2 != null) { metadata.add(sub2); } } Address[] replyTo = null; try { replyTo = message.getReplyTo(); if (replyTo != null && replyTo.length > 0) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.replyTo.name); for (Address address : replyTo) { addAddress(sub, EMAIL_FIELDS.fromUnit.name, address, null); } metadata.add(sub); } } catch (MessagingException e1) { String[] partialResult; try { partialResult = message.getHeader("ReplyTo"); if (partialResult != null && partialResult.length > 0) { sub2 = XmlDom.factory.createElement(EMAIL_FIELDS.replyTo.name); addAddress(sub2, EMAIL_FIELDS.fromUnit.name, partialResult, null); /*Element add = XmlDom.factory.createElement(EMAIL_FIELDS.fromUnit.name); add.setText(partialResult[0]); sub2.add(add);*/ metadata.add(sub2); } } catch (MessagingException e) { } } Address[] toRecipients = null; try { toRecipients = message.getRecipients(Message.RecipientType.TO); if (toRecipients != null && toRecipients.length > 0) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.toRecipients.name); for (Address address : toRecipients) { addAddress(sub, EMAIL_FIELDS.toUnit.name, address, null); } metadata.add(sub); } } catch (MessagingException e1) { String[] partialResult; try { partialResult = message.getHeader("To"); if (partialResult != null && partialResult.length > 0) { sub2 = XmlDom.factory.createElement(EMAIL_FIELDS.toRecipients.name); addAddress(sub2, EMAIL_FIELDS.toUnit.name, partialResult, null); /*for (String string : partialResult) { Element add = XmlDom.factory.createElement(EMAIL_FIELDS.toUnit.name); add.setText(string); sub2.add(add); }*/ metadata.add(sub2); } } catch (MessagingException e) { } } Address[] ccRecipients; try { ccRecipients = message.getRecipients(Message.RecipientType.CC); if (ccRecipients != null && ccRecipients.length > 0) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.ccRecipients.name); for (Address address : ccRecipients) { addAddress(sub, EMAIL_FIELDS.ccUnit.name, address, null); } metadata.add(sub); } } catch (MessagingException e1) { String[] partialResult; try { partialResult = message.getHeader("Cc"); if (partialResult != null && partialResult.length > 0) { sub2 = XmlDom.factory.createElement(EMAIL_FIELDS.ccRecipients.name); addAddress(sub2, EMAIL_FIELDS.ccUnit.name, partialResult, null); /*for (String string : partialResult) { Element add = XmlDom.factory.createElement(EMAIL_FIELDS.ccUnit.name); add.setText(string); sub2.add(add); }*/ metadata.add(sub2); } } catch (MessagingException e) { } } Address[] bccRecipients; try { bccRecipients = message.getRecipients(Message.RecipientType.BCC); if (bccRecipients != null && bccRecipients.length > 0) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.bccRecipients.name); for (Address address : bccRecipients) { addAddress(sub, EMAIL_FIELDS.bccUnit.name, address, null); } metadata.add(sub); } } catch (MessagingException e1) { String[] partialResult; try { partialResult = message.getHeader("Cc"); if (partialResult != null && partialResult.length > 0) { sub2 = XmlDom.factory.createElement(EMAIL_FIELDS.bccRecipients.name); addAddress(sub2, EMAIL_FIELDS.bccUnit.name, partialResult, null); /*for (String string : partialResult) { Element add = XmlDom.factory.createElement(EMAIL_FIELDS.bccUnit.name); add.setText(string); sub2.add(add); }*/ metadata.add(sub2); } } catch (MessagingException e) { } } try { String subject = message.getSubject(); if (subject != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.subject.name); sub.setText(StringUtils.unescapeHTML(subject, true, false)); metadata.add(sub); } Date sentDate = message.getSentDate(); if (sentDate != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.sentDate.name); sub.setText(sentDate.toString()); metadata.add(sub); } Date receivedDate = message.getReceivedDate(); if (receivedDate != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.receivedDate.name); sub.setText(receivedDate.toString()); metadata.add(sub); } String[] headers = message.getHeader("Received"); if (headers != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.receptionTrace.name); MailDateFormat mailDateFormat = null; long maxTime = 0; if (receivedDate == null) { mailDateFormat = new MailDateFormat(); } for (String string : headers) { Element sub3 = XmlDom.factory.createElement(EMAIL_FIELDS.trace.name); sub3.setText(StringUtils.unescapeHTML(string, true, false)); sub.add(sub3); if (receivedDate == null) { int pos = string.lastIndexOf(';'); if (pos > 0) { String recvdate = string.substring(pos + 2).replaceAll("\t\n\r\f", "").trim(); try { Date date = mailDateFormat.parse(recvdate); if (date.getTime() > maxTime) { maxTime = date.getTime(); } } catch (ParseException e) { } } } } if (receivedDate == null) { Element subdate = XmlDom.factory.createElement(EMAIL_FIELDS.receivedDate.name); Date date = new Date(maxTime); subdate.setText(date.toString()); metadata.add(subdate); } metadata.add(sub); } int internalSize = message.getSize(); if (internalSize > 0) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.emailSize.name); sub.setText(Integer.toString(internalSize)); metadata.add(sub); } String encoding = message.getEncoding(); if (encoding != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.encoding.name); sub.setText(StringUtils.unescapeHTML(encoding, true, false)); metadata.add(sub); } String description = message.getDescription(); if (description != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.description.name); sub.setText(StringUtils.unescapeHTML(description, true, false)); metadata.add(sub); } String contentType = message.getContentType(); if (contentType != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.contentType.name); sub.setText(StringUtils.unescapeHTML(contentType, true, false)); metadata.add(sub); } headers = message.getHeader("Content-Transfer-Encoding"); if (headers != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.contentTransferEncoding.name); StringBuilder builder = new StringBuilder(); for (String string : headers) { builder.append(StringUtils.unescapeHTML(string, true, false)); builder.append(' '); } sub.setText(builder.toString()); metadata.add(sub); } String[] contentLanguage = message.getContentLanguage(); if (contentLanguage != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.contentLanguage.name); StringBuilder builder = new StringBuilder(); for (String string : contentLanguage) { builder.append(StringUtils.unescapeHTML(string, true, false)); builder.append(' '); } sub.setText(builder.toString()); metadata.add(sub); } String contentId = message.getContentID(); if (contentId != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.contentId.name); sub.setText(StringUtils.removeChevron(StringUtils.unescapeHTML(contentId, true, false))); metadata.add(sub); } String disposition = message.getDisposition(); if (disposition != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.disposition.name); sub.setText(StringUtils.removeChevron(StringUtils.unescapeHTML(disposition, true, false))); metadata.add(sub); } headers = message.getHeader("Keywords"); if (headers != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.msgKeywords.name); StringBuilder builder = new StringBuilder(); for (String string : headers) { builder.append(StringUtils.unescapeHTML(string, true, false)); builder.append(' '); } sub.setText(builder.toString()); metadata.add(sub); } String messageId = message.getMessageID(); if (messageId != null) { messageId = StringUtils.removeChevron(StringUtils.unescapeHTML(messageId, true, false)).trim(); if (messageId.length() > 1) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.messageId.name); sub.setText(messageId); metadata.add(sub); } } headers = message.getHeader("In-Reply-To"); String inreplyto = null; if (headers != null) { StringBuilder builder = new StringBuilder(); for (String string : headers) { builder.append(StringUtils.removeChevron(StringUtils.unescapeHTML(string, true, false))); builder.append(' '); } inreplyto = builder.toString().trim(); if (inreplyto.length() > 0) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.inReplyTo.name); sub.setText(inreplyto); if (messageId != null && messageId.length() > 1) { String old = filEmls.get(inreplyto); if (old == null) { old = messageId; } else { old += "," + messageId; } filEmls.put(inreplyto, old); } metadata.add(sub); } } headers = message.getHeader("References"); if (headers != null) { Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.references.name); StringBuilder builder = new StringBuilder(); for (String string : headers) { builder.append(StringUtils.removeChevron(StringUtils.unescapeHTML(string, true, false))); builder.append(' '); } String[] refs = builder.toString().trim().split(" "); for (String string : refs) { if (string.length() > 0) { Element ref = XmlDom.factory.createElement(EMAIL_FIELDS.reference.name); ref.setText(string); sub.add(ref); } } metadata.add(sub); } Element prop = XmlDom.factory.createElement(EMAIL_FIELDS.properties.name); headers = message.getHeader("X-Priority"); if (headers == null) { headers = message.getHeader("Priority"); if (headers != null && headers.length > 0) { prop.addAttribute(EMAIL_FIELDS.priority.name, headers[0]); } } else if (headers != null && headers.length > 0) { String imp = headers[0]; try { int Priority = Integer.parseInt(imp); switch (Priority) { case 5: imp = "LOWEST"; break; case 4: imp = "LOW"; break; case 3: imp = "NORMAL"; break; case 2: imp = "HIGH"; break; case 1: imp = "HIGHEST"; break; default: imp = "LEV" + Priority; } } catch (NumberFormatException e) { // ignore since imp will be used as returned } prop.addAttribute(EMAIL_FIELDS.priority.name, imp); } headers = message.getHeader("Sensitivity"); if (headers != null && headers.length > 0) { prop.addAttribute(EMAIL_FIELDS.sensitivity.name, headers[0]); } headers = message.getHeader("X-RDF"); if (headers != null && headers.length > 0) { System.err.println("Found X-RDF"); StringBuilder builder = new StringBuilder(); for (String string : headers) { builder.append(string); builder.append("\n"); } try { byte[] decoded = org.apache.commons.codec.binary.Base64.decodeBase64(builder.toString()); String rdf = new String(decoded); Document tempDocument = DocumentHelper.parseText(rdf); Element xrdf = prop.addElement("x-rdf"); xrdf.add(tempDocument.getRootElement()); } catch (Exception e) { System.err.println("Cannot decode X-RDF: " + e.getMessage()); } } try { File old = argument.currentOutputDir; if (config.extractFile) { File newOutDir = new File(argument.currentOutputDir, id); newOutDir.mkdirs(); argument.currentOutputDir = newOutDir; } if (argument.extractKeyword) { skey = handleMessage(message, metadata, prop, id, argument, config); // should have hasAttachment if (prop.hasContent()) { metadata.add(prop); } if (metadata.hasContent()) { root.add(metadata); } ExtractInfo.exportMetadata(keywords, skey, "", config, null); if (keywords.hasContent()) { root.add(keywords); } } else { handleMessage(message, metadata, prop, id, argument, config); // should have hasAttachment if (prop.hasContent()) { metadata.add(prop); } if (metadata.hasContent()) { root.add(metadata); } } argument.currentOutputDir = old; } catch (IOException e) { System.err.println(StaticValues.LBL.error_error.get() + e.toString()); } try { message.getInputStream().close(); } catch (IOException e) { System.err.println(StaticValues.LBL.error_error.get() + e.toString()); } root.addAttribute(EMAIL_FIELDS.status.name, "ok"); } catch (MessagingException e) { System.err.println(StaticValues.LBL.error_error.get() + e.toString()); e.printStackTrace(); String status = "Error during identification"; root.addAttribute(EMAIL_FIELDS.status.name, status); } catch (Exception e) { System.err.println(StaticValues.LBL.error_error.get() + e.toString()); e.printStackTrace(); String status = "Error during identification"; root.addAttribute(EMAIL_FIELDS.status.name, status); } argument.currentOutputDir = oldDir; return skey; }