List of usage examples for org.apache.commons.mail HtmlEmail setHostName
public void setHostName(final String aHostName)
From source file:de.maklerpoint.office.Schnittstellen.Email.MultiEmailSender.java
public void send() throws EmailException { if (files != null && urls != null) { attachments = new EmailAttachment[files.length + urls.length]; int cnt = 0; for (int i = 0; i < files.length; i++) { attachments[cnt] = new EmailAttachment(); attachments[cnt].setPath(files[i].getPath()); attachments[cnt].setName(files[i].getName()); attachments[cnt].setDisposition(EmailAttachment.ATTACHMENT); cnt++;/*w w w .ja v a 2s .c o m*/ } for (int i = 0; i < urls.length; i++) { attachments[cnt] = new EmailAttachment(); attachments[cnt].setURL(urls[i]); attachments[cnt].setName(urls[i].getFile()); attachments[cnt].setDisposition(EmailAttachment.ATTACHMENT); cnt++; } } else if (files != null) { attachments = new EmailAttachment[files.length]; for (int i = 0; i < files.length; i++) { attachments[i] = new EmailAttachment(); attachments[i].setPath(files[i].getPath()); attachments[i].setName(files[i].getName()); attachments[i].setDisposition(EmailAttachment.ATTACHMENT); } } else if (urls != null) { attachments = new EmailAttachment[urls.length]; for (int i = 0; i < urls.length; i++) { attachments[i] = new EmailAttachment(); attachments[i].setURL(urls[i]); attachments[i].setName(urls[i].getFile()); attachments[i].setDisposition(EmailAttachment.ATTACHMENT); } } HtmlEmail email = new HtmlEmail(); email.setHostName(Config.get("mailHost", "")); email.setSmtpPort(Config.getConfigInt("mailPort", 25)); email.setTLS(Config.getConfigBoolean("mailTLS", false)); email.setSSL(Config.getConfigBoolean("mailSSL", false)); //email.setSslSmtpPort(Config.getConfigInt("emailPort", 25)); email.setAuthenticator( new DefaultAuthenticator(Config.get("mailUsername", ""), Config.get("mailPassword", ""))); email.setFrom(Config.get("mailSendermail", "info@example.de"), Config.get("mailSender", null)); email.setSubject(subject); email.setHtmlMsg(body); email.setTextMsg(nohtmlmsg); for (int i = 0; i < adress.length; i++) { email.addTo(adress[i]); } if (cc != null) { for (int i = 0; i < cc.length; i++) { email.addCc(cc[i]); } } if (attachments != null) { for (int i = 0; i < attachments.length; i++) { email.attach(attachments[i]); } } email.send(); }
From source file:com.aquest.emailmarketing.web.service.SendEmail.java
/** * Send email.//from www.j a v a 2 s .com * * @param broadcast the broadcast * @param emailConfig the email config * @param emailList the email list * @throws EmailException the email exception * @throws MalformedURLException the malformed url exception * @throws InterruptedException the interrupted exception */ @Async public void sendEmail(Broadcast broadcast, EmailConfig emailConfig, EmailList emailList) throws EmailException, MalformedURLException, InterruptedException { Timestamp curTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()); // email configuration part HtmlEmail email = new HtmlEmail(); email.setSmtpPort(emailConfig.getPort()); email.setHostName(emailConfig.getHostname()); email.setAuthenticator(new DefaultAuthenticator(emailConfig.getUsername(), emailConfig.getPassword())); email.setSSLOnConnect(emailConfig.isSslonconnect()); email.setDebug(emailConfig.isDebug()); email.setFrom(emailConfig.getFrom_address()); //ovde dodati i email from description System.out.println(emailList); HashMap<String, String> variables = processVariableService.ProcessVariable(emailList); for (String keys : variables.keySet()) { System.out.println("key:" + keys + ", value:" + variables.get(keys)); } String processSubject = broadcast.getSubject(); String newHtml = broadcast.getHtmlbody_embed(); String newPlainText = broadcast.getPlaintext(); for (String key : variables.keySet()) { processSubject = processSubject.replace("[" + key + "]", variables.get(key)); System.out.println(key + "-" + variables.get(key)); newHtml = newHtml.replace("[" + key + "]", variables.get(key)); newPlainText = newPlainText.replace("[" + key + "]", variables.get(key)); } System.out.println(processSubject); email.setSubject(processSubject); email.addTo(emailList.getEmail()); String image = embeddedImageService.getEmbeddedImages(broadcast.getBroadcast_id()).getUrl(); List<String> images = Arrays.asList(image.split(";")); for (int j = 0; j < images.size(); j++) { System.out.println(images.get(j)); } for (int i = 0; i < images.size(); i++) { String id = email.embed(images.get(i), "Slika" + i); newHtml = newHtml.replace("[IMAGE:" + i + "]", "cid:" + id); } Config config = configService.getConfig("trackingurl"); //DONE: Create jsp page for tracking server url String serverUrl = config.getValue(); System.out.println(serverUrl); Base64 base64 = new Base64(true); Pattern pattern = Pattern.compile("<%tracking=(.*?)=tracking%>"); Matcher matcher = pattern.matcher(newHtml); while (matcher.find()) { String url = matcher.group(1); System.out.println(url); logger.debug(url); String myEncryptedUrl = new String(base64.encode(url.getBytes())); String oldurl = "<%tracking=" + url + "=tracking%>"; logger.debug(oldurl); System.out.println(oldurl); String newurl = serverUrl + "tracking?id=" + myEncryptedUrl; logger.debug(newurl); System.out.println(newurl); newHtml = newHtml.replace(oldurl, newurl); } // System.out.println(newHtml); email.setHtmlMsg(newHtml); email.setTextMsg(newPlainText); try { System.out.println("A ovo ovde?"); email.send(); emailList.setStatus("SENT"); emailList.setProcess_dttm(curTimestamp); emailListService.SaveOrUpdate(emailList); } catch (Exception e) { logger.error(e); } // time in seconds to wait between 2 mails TimeUnit.SECONDS.sleep(emailConfig.getWait()); }
From source file:com.jredrain.service.NoticeService.java
public void sendMessage(Long receiverId, Long workId, String emailAddress, String mobiles, String content) { Log log = new Log(); log.setIsread(0);//from w ww . j a va2 s . co m log.setAgentId(workId); log.setMessage(content); //??? if (CommonUtils.isEmpty(emailAddress, mobiles)) { log.setType(RedRain.MsgType.WEBSITE.getValue()); log.setSendTime(new Date()); homeService.saveLog(log); return; } /** * ???? */ boolean emailSuccess = false; boolean mobileSuccess = false; try { log.setType(RedRain.MsgType.EMAIL.getValue()); HtmlEmail email = new HtmlEmail(); email.setCharset("UTF-8"); email.setHostName(config.getSmtpHost()); email.setSslSmtpPort(config.getSmtpPort().toString()); email.setAuthentication(config.getSenderEmail(), config.getPassword()); email.setFrom(config.getSenderEmail()); email.setSubject("redrain"); email.setHtmlMsg(msgToHtml(receiverId, content)); email.addTo(emailAddress.split(",")); email.send(); emailSuccess = true; /** * ?? */ log.setReceiver(emailAddress); log.setSendTime(new Date()); homeService.saveLog(log); } catch (Exception e) { e.printStackTrace(System.err); } /** * ???? */ try { for (String mobile : mobiles.split(",")) { //??POST String sendUrl = String.format(config.getSendUrl(), mobile, String.format(config.getTemplate(), content)); String url = sendUrl.substring(0, sendUrl.indexOf("?")); String postData = sendUrl.substring(sendUrl.indexOf("?") + 1); String message = HttpUtils.doPost(url, postData, "UTF-8"); log.setResult(message); logger.info(message); mobileSuccess = true; } log.setReceiver(mobiles); log.setType(RedRain.MsgType.SMS.getValue()); log.setSendTime(new Date()); homeService.saveLog(log); } catch (Exception e) { e.printStackTrace(System.err); } /** * ??,?? */ if (!mobileSuccess && !emailSuccess) { log.setType(RedRain.MsgType.WEBSITE.getValue()); log.setSendTime(new Date()); homeService.saveLog(log); } }
From source file:com.ipc.service.SignUpService.java
public String sendhtmlmail(int uid, String key, String email) throws IOException, EmailException { HtmlEmail sendemail = new HtmlEmail(); sendemail.setCharset("euc-kr"); sendemail.setHostName("smtp.worksmobile.com"); sendemail.addTo(email);/*from w w w . j ava 2 s .c o m*/ sendemail.setFrom("jinuk@ideaconcert.com", ""); sendemail.setSubject("? ?? ?."); sendemail.setAuthentication("jinuk@ideaconcert.com", "tpxmapsb1"); sendemail.setSmtpPort(465); sendemail.setSSL(true); //? sendemail.setTLS(true); sendemail.setDebug(true); String htmlmsg = "<html><div style='width:1000px; float:left; border-bottom:2px solid #45d4fe; padding-bottom:5px;box-sizing:border-box;'></div><div style='width:1000px;float:left; box-sizing:border-box; padding:15px;'><h2>? ? ? .</h2><div style='width:100%; float:left; box-sizing:border-box; border:5px solid #f9f9f9; text-align:center; padding:40px 0 40px 0;'><span> ? .</span><br><a href='http://localhost:8088/signup/permit?uid=" + uid + "&key=" + key + "'><button style='width:150px; height:40px; background:none; border:2px solid #45d4fe; font-size:1.1rem; text-decoration: none;font-weight:bold; margin-top:10px;'></button></a></div></div></html>"; System.out.println(htmlmsg); sendemail.setHtmlMsg(htmlmsg); try { sendemail.send(); } catch (Exception e) { System.out.println("NOTOK"); return "NOTOK"; } return "OK"; }
From source file:com.ipc.service.SignUpService.java
public String sendpwmail(int uid, String key, String email) throws IOException, EmailException { System.out.println("Email : " + email); HtmlEmail sendemail = new HtmlEmail(); sendemail.setCharset("euc-kr"); sendemail.setHostName("smtp.worksmobile.com"); sendemail.addTo(email);// ww w .ja v a 2 s . com sendemail.setFrom("jinuk@ideaconcert.com", ""); sendemail.setSubject("? ."); sendemail.setAuthentication("jinuk@ideaconcert.com", "tpxmapsb1"); sendemail.setSmtpPort(465); sendemail.setSSL(true); //? sendemail.setTLS(true); sendemail.setDebug(true); String htmlmsg = "<html><div style='width:1000px; float:left; border-bottom:2px solid #45d4fe; padding-bottom:5px;box-sizing:border-box;'></div><div style='width:1000px;float:left; box-sizing:border-box; padding:15px;'><h2>? .</h2><div style='width:100%; float:left; box-sizing:border-box; border:5px solid #f9f9f9; text-align:center; padding:40px 0 40px 0;'><span> ? <br> .<br>" + key + "</span></html>"; System.out.println(htmlmsg); sendemail.setHtmlMsg(htmlmsg); try { sendemail.send(); } catch (Exception e) { System.out.println("NOTOK"); return "NOTOK"; } return "OK"; }
From source file:Email.CommonsEmail.java
/** * funo para enviar email//w ww. j a v a 2s. c o m * * @param titulo * @param msgEmail * @param emailDestinatarios * @return */ public boolean enviarEmail(String titulo, String msgEmail, String emailDestinatarios) { boolean enviado = false; String para = emailDestinatarios.toLowerCase().trim(); String subject = titulo.trim(); String msg = msgEmail.trim(); try { StringTokenizer stPara = new StringTokenizer(para, ";"); while (stPara.hasMoreTokens()) { if (!stPara.toString().trim().equals("")) { HtmlEmail email = new HtmlEmail(); /*o servidor SMTP para envio do e-mail*/ email.setHostName(emailConfig.getHostname()); email.setSmtpPort(emailConfig.getPorta()); email.setSSLOnConnect(emailConfig.getSsl()); email.setStartTLSEnabled(emailConfig.getTsl()); /*remetente*/ email.setFrom(emailConfig.getEmail(), emailConfig.getNome()); email.setAuthentication(emailConfig.getUsuario(), emailConfig.getSenha()); /* ---------------------------------------------------------- */ //destinatrio //email.addTo(emailDestinatario, nomeDestinatario); email.addTo(stPara.nextToken().trim()); // assunto do e-mail email.setSubject(subject); //conteudo do e-mail //configura a mensagem para o formato HTML email.setHtmlMsg(msg); // configure uma mensagem alternativa caso o servidor no suporte HTML email.setTextMsg("Seu servidor de e-mail no suporta mensagem HTML"); // envia email email.send(); enviado = true; } } } catch (EmailException ex) { enviado = false; Logger.getLogger(CommonsEmail.class.getName()).log(Level.SEVERE, null, ex); } return enviado; }
From source file:com.perceptive.epm.perkolcentral.bl.EmployeeBL.java
private void sendMailToPerceptiveOpsTeam(EmployeeBO employeeBO) throws Exception { try {/*from w ww .jav a 2s . c om*/ //Send the mail HtmlEmail emailToSend = new HtmlEmail(); emailToSend.setHostName(email.getHostName()); String messageTemplateAdded = "<html>\n" + "<head>\n" + "</head>\n" + "\n" + "<body style=\"font:Georgia; font-size:12px;\">\n" + "<p>Dear All,</p>\n" + "<blockquote>\n" + " <p>A new employee has joined Perceptive Kolkata.</p>\n" + "</blockquote>\n" + "<ul>\n" + " <li><strong><em>User Name</em></strong>: <strong>%s</strong></li>\n" + " <li><em><strong>User Short Id</strong></em>: <strong>%s</strong></li>\n" + " <li><em><strong>Employee Id</strong></em>: <strong>%s</strong></li>\n" + " <li><strong><em>User Email-Id</em></strong>:<strong> %s</strong></li>\n" + " <li><em><strong>Mobile Number</strong></em>:<strong> %s</strong></li>\n" + " <li><em><strong>Job Title</strong></em> : <strong>%s</strong></li>\n" + "</ul>\n" + "<p>Please take following actions.</p>\n" + "<ul>\n" + " <li>Access to Rally.</li>\n" + " <li>Access to Salesforce.</li>\n" + " <li>Access to Confluence.</li>\n" + " <li>Access to Perceptive AD.</li>\n" + " <li>Access to TFS.</li>\n" + "</ul>\n" + "<p>Thanks,</p>\n" + "<blockquote>\n" + " <p>Perceptive Kolkata Central( http://10.195.17.14/PerceptiveKolkataCentral )</p>\n" + "</blockquote>\n" + "</body>\n" + "</html>"; String messageToSend = String.format(messageTemplateAdded, employeeBO.getEmployeeName(), employeeBO.getEmployeeUid(), employeeBO.getEmployeeId().toString(), employeeBO.getEmail(), employeeBO.getMobileNumber(), employeeBO.getJobTitle()); emailToSend.setHtmlMsg(messageToSend); //emailToSend.setTextMsg(StringEscapeUtils.escapeHtml(messageToSend)); emailToSend.getToAddresses().clear(); emailToSend.addTo("per.special.rad.operations@perceptivesoftware.com", "RAD - Operations"); emailToSend.addTo("radops@perceptivesoftware.com", "RAD - Operations Team"); Collection<EmployeeBO> allEmployeesNeedToGetMail = getAllEmployeesKeyedByGroupId() .get(Integer.valueOf("14")); for (EmployeeBO item : allEmployeesNeedToGetMail) { emailToSend.addCc(item.getEmail(), item.getEmployeeName()); } //emailToSend.setFrom("PerceptiveKolkataCentral@perceptivesoftware.com", "Perceptive Kolkata Central"); emailToSend.setFrom("EnterpriseSoftwareKolkata@lexmark.com", "Enterprise Software Kolkata"); emailToSend.setSubject( String.format("New employee joined @ Lexmark Kolkata : %s", employeeBO.getEmployeeName())); emailToSend.send(); } catch (Exception ex) { throw new ExceptionWrapper(ex); } }
From source file:com.jnd.sonar.analysisreport.AnalysisReportHelper.java
private void sendEmail(String reportname, Map<String, String> reportDataMap2) { try {//from ww w . j av a2s . co m // Create the email message //MultiPartEmail email = new MultiPartEmail(); StringBuilder strHtmlContentSummary = new StringBuilder(); System.out.println("Analysis - Sonar Email Notification"); from = settings.getString("sonar.jd.smptp.username"); System.out.println("from=>" + from); to_email = settings.getString("sonar.jd.smptp.to"); System.out.println("to_email=>" + to_email); to_email_name = settings.getString("sonar.jd.smptp.to_name"); System.out.println("to_email_name=>" + to_email_name); username = settings.getString("sonar.jd.smptp.username"); System.out.println("username=>" + username); password = settings.getString("sonar.jd.smptp.password"); System.out.println("password=>" + password); hostname = settings.getString("sonar.jd.smptp.host"); System.out.println("hostname=>" + hostname); portno = settings.getString("sonar.jd.smptp.sslport"); System.out.println("portno=>" + portno); setSSLOnConnectFlag = settings.getBoolean("sonar.jd.smptp.set_ssl_on_connect"); System.out.println("setSSLOnConnectFlag=>" + String.valueOf(setSSLOnConnectFlag)); subject = settings.getString("sonar.jd.smptp.subject"); System.out.println("subject=>" + subject); message = settings.getString("sonar.jd.smptp.message"); System.out.println("message=>" + message); // Create the email message HtmlEmail email = new HtmlEmail(); email.setHostName(hostname); email.setSslSmtpPort(portno); if (!StringUtils.isBlank(username) || !StringUtils.isBlank(password)) { email.setAuthentication(username, password); } //email.setSSLOnConnect(setSSLOnConnectFlag); email.setSSL(setSSLOnConnectFlag); String[] addrs = StringUtils.split(to_email, "\t\r\n;, "); for (String addr : addrs) { email.addTo(addr); } //email.addTo(to_email,to_email_name); email.setFrom(from); email.setSubject(subject); //email.setMsg(message); // embed the image and get the content id URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif"); String cid = email.embed(url, "Apache logo - 1"); System.out.println("Print Entries from Analysis Data Map."); int i = 1; strHtmlContentSummary.append("<html><body>The apache logo - <img src=\"cid:" + cid + "\"><br><br><br><b><center>Metric Information:-</center></b><br><table border='2'>"); for (Map.Entry<String, String> entry : reportDataMap.entrySet()) { strHtmlContentSummary .append("<tr><td>" + entry.getKey() + ":</td><td>" + entry.getValue() + "</td></tr>"); i++; } strHtmlContentSummary.append("</table></body></html>"); System.out.println(strHtmlContentSummary.toString()); // set the html message email.setHtmlMsg(strHtmlContentSummary.toString()); // set the alternative message email.setTextMsg("Your email client does not support HTML messages"); // Create the attachment EmailAttachment attachment = new EmailAttachment(); attachment.setPath(reportname); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Sonar Analysis Report" + reportname); attachment.setName(reportname); email.attach(attachment); // send the email System.out.println("Sending the Email"); email.send(); } catch (EmailException e) { throw new SonarException("Unable to send email", e); } catch (Exception ex) { // TODO Auto-generated catch block ex.printStackTrace(); } }
From source file:com.perceptive.epm.perkolcentral.bl.EmployeeBL.java
@TriggersRemove(cacheName = { "EmployeeCache", "GroupCache", "EmployeeKeyedByGroupCache" }, when = When.AFTER_METHOD_INVOCATION, removeAll = true, keyGenerator = @KeyGenerator(name = "HashCodeCacheKeyGenerator", properties = @Property(name = "includeMethod", value = "false"))) @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, rollbackFor = ExceptionWrapper.class) public void updateAllEmployee(List<EmployeeBO> employeeListFromLDAP) throws ExceptionWrapper { try {/*w ww. j av a 2 s . c o m*/ String messageTemplateAdded = "<html>\n" + "<head>\n" + "</head>\n" + "\n" + "<body style=\"font:Georgia; font-size:12px;\">\n" + "<p>Dear All,</p>\n" + "<blockquote>\n" + " <p>A new user is added to the system.</p>\n" + "</blockquote>\n" + "<ul>\n" + " <li><strong><em>User Name</em></strong>: <strong>%s</strong></li>\n" + " <li><em><strong>User Short Id</strong></em>: <strong>%s</strong></li>\n" + " <li><em><strong>Employee Id</strong></em>: <strong>%s</strong></li>\n" + " <li><strong><em>User Email-Id</em></strong>:<strong> %s</strong></li>\n" + " <li><em><strong>Mobile Number</strong></em>:<strong> %s</strong></li>\n" + " <li><em><strong>Job Title</strong></em> : <strong>%s</strong></li>\n" + "</ul>\n" + "<p>Please take necessary actions.</p>\n" + "<p>Thanks,</p>\n" + "<blockquote>\n" + " <p>Perceptive Kolkata Central</p>\n" + "</blockquote>\n" + "</body>\n" + "</html>"; String messageTemplateDeleted = "<html>\n" + "<head>\n" + "</head>\n" + "\n" + "<body style=\"font:Georgia; font-size:12px;\">\n" + "<p>Dear All,</p>\n" + "<blockquote>\n" + " <p>An user is removed from the system.</p>\n" + "</blockquote>\n" + "<ul>\n" + " <li><strong><em>User Name</em></strong>: <strong>%s</strong></li>\n" + " <li><em><strong>User Short Id</strong></em>: <strong>%s</strong></li>\n" + " <li><em><strong>Employee Id</strong></em>: <strong>%s</strong></li>\n" + " <li><strong><em>User Email-Id</em></strong>:<strong> %s</strong></li>\n" + " <li><em><strong>Mobile Number</strong></em>:<strong> %s</strong></li>\n" + " <li><em><strong>Job Title</strong></em> : <strong>%s</strong></li>\n" + "</ul>\n" + "<p>Please take necessary actions.</p>\n" + "<p>Thanks,</p>\n" + "<blockquote>\n" + " <p>Perceptive Kolkata Central</p>\n" + "</blockquote>\n" + "</body>\n" + "</html>"; LinkedHashMap<Long, EmployeeBO> employeeLinkedHashMap = employeeDataAccessor.getAllEmployees(); for (EmployeeBO employeeBO : employeeListFromLDAP) { if (!employeeLinkedHashMap.containsKey(Long.valueOf(employeeBO.getEmployeeId()))) { //Add a new employee Employee employee = new Employee(); employee.setEmployeeId(Long.parseLong(employeeBO.getEmployeeId())); employee.setEmail(employeeBO.getEmail()); employee.setEmployeeName(employeeBO.getEmployeeName()); employee.setEmployeeUid(employeeBO.getEmployeeUid()); employee.setJobTitle(employeeBO.getJobTitle()); employee.setMobileNumber(employeeBO.getMobileNumber()); employee.setManager(employeeBO.getManager()); employee.setManagerEmail(employeeBO.getManagerEmail()); employee.setExtensionNum(employeeBO.getExtensionNum()); employee.setWorkspace(employeeBO.getWorkspace()); employee.setIsActive(true); employeeDataAccessor.addEmployee(employee); LoggingHelpUtil.printDebug(String.format("Adding user ----> %s with details %s %s", employeeBO.getEmployeeName(), System.getProperty("line.separator"), ReflectionToStringBuilder.toString(employeeBO))); //Send the mail HtmlEmail emailToSend = new HtmlEmail(); emailToSend.setHostName(email.getHostName()); String messageToSend = String.format(messageTemplateAdded, employeeBO.getEmployeeName(), employeeBO.getEmployeeUid(), employeeBO.getEmployeeId().toString(), employeeBO.getEmail(), employeeBO.getMobileNumber(), employeeBO.getJobTitle()); emailToSend.setHtmlMsg(messageToSend); //emailToSend.setTextMsg(StringEscapeUtils.escapeHtml(messageToSend)); emailToSend.getToAddresses().clear(); //Send mail to scrum masters and Development Managers Group Id 15 Collection<EmployeeBO> allEmployeesNeedToGetMail = CollectionUtils.union( getAllEmployeesKeyedByGroupId().get(Integer.valueOf("14")), getAllEmployeesKeyedByGroupId().get(Integer.valueOf("15"))); for (EmployeeBO item : allEmployeesNeedToGetMail) { emailToSend.addTo(item.getEmail(), item.getEmployeeName()); } emailToSend.addTo(employeeBO.getManagerEmail(), employeeBO.getManager());//Send the mail to manager //emailToSend.setFrom("PerceptiveKolkataCentral@perceptivesoftware.com", "Perceptive Kolkata Central"); emailToSend.setFrom("EnterpriseSoftwareKolkata@lexmark.com", "Enterprise Software Kolkata"); emailToSend.setSubject(String.format("New employee added : %s", employeeBO.getEmployeeName())); emailToSend.send(); //==========================Mail send ends here=========================================================================================================== //sendMailToPerceptiveOpsTeam(employeeBO);//Send mail to operations team in Shawnee } else { //Update a new employee employeeDataAccessor.updateEmployee(employeeBO); LoggingHelpUtil.printDebug(String.format("Updating user ----> %s with details %s %s", employeeBO.getEmployeeName(), System.getProperty("line.separator"), ReflectionToStringBuilder.toString(employeeBO))); } //======================================================================================================================================== } //Delete employees if any for (Object obj : employeeLinkedHashMap.values()) { final EmployeeBO emp = (EmployeeBO) obj; if (!CollectionUtils.exists(employeeListFromLDAP, new Predicate() { @Override public boolean evaluate(Object o) { return emp.getEmployeeId().trim().equalsIgnoreCase(((EmployeeBO) o).getEmployeeId().trim()); //To change body of implemented methods use File | Settings | File Templates. } })) { emp.setActive(false); //Soft delete the Employee employeeDataAccessor.updateEmployee(emp);//Rest deletion will be taken care by the Trigger AFTER_EMPLOYEE_UPDATE LoggingHelpUtil.printDebug( String.format("Deleting user ----> %s with details %s %s", emp.getEmployeeName(), System.getProperty("line.separator"), ReflectionToStringBuilder.toString(emp))); //Send the mail HtmlEmail emailToSend = new HtmlEmail(); emailToSend.setHostName(email.getHostName()); String messageToSend = String.format(messageTemplateDeleted, emp.getEmployeeName(), emp.getEmployeeUid(), emp.getEmployeeId().toString(), emp.getEmail(), emp.getMobileNumber(), emp.getJobTitle()); emailToSend.setHtmlMsg(messageToSend); //emailToSend.setTextMsg(StringEscapeUtils.escapeHtml(messageToSend)); emailToSend.getToAddresses().clear(); //Send mail to scrum masters ==Group ID 14 and Development Managers Group Id 15 Collection<EmployeeBO> allEmployeesNeedToGetMail = CollectionUtils.union( getAllEmployeesKeyedByGroupId().get(Integer.valueOf("14")), getAllEmployeesKeyedByGroupId().get(Integer.valueOf("15"))); for (EmployeeBO item : allEmployeesNeedToGetMail) { emailToSend.addTo(item.getEmail(), item.getEmployeeName()); } //emailToSend.setFrom("PerceptiveKolkataCentral@perceptivesoftware.com", "Perceptive Kolkata Central"); emailToSend.setFrom("EnterpriseSoftwareKolkata@lexmark.com", "Enterprise Software Kolkata"); emailToSend.setSubject(String.format("Employee removed : %s", emp.getEmployeeName())); emailToSend.send(); } } luceneUtil.indexUserInfo(getAllEmployees().values()); } catch (Exception ex) { throw new ExceptionWrapper(ex); } }
From source file:br.ufg.reqweb.components.MailBean.java
public void sendMailToDiscente(final Requerimento requerimento) { Thread sender = new Thread() { @Override/* ww w. j av a 2 s . co m*/ public void run() { try { Configuration templateConf = new Configuration(); templateConf.setObjectWrapper(new DefaultObjectWrapper()); templateConf.setDefaultEncoding("UTF-8"); templateConf.setDirectoryForTemplateLoading(new File(context.getRealPath("/reports/mail"))); Map objectRoot = new HashMap(); objectRoot.put("TITULO", LocaleBean.getDefaultMessageBundle().getString("appTitle")); objectRoot.put("DISCENTE", LocaleBean.getDefaultMessageBundle().getString("discente")); objectRoot.put("REQUERIMENTO", LocaleBean.getDefaultMessageBundle().getString("requerimento")); objectRoot.put("STATUS", LocaleBean.getDefaultMessageBundle().getString("status")); objectRoot.put("ATENDENTE", LocaleBean.getDefaultMessageBundle().getString("atendente")); objectRoot.put("OBSERVACAO", LocaleBean.getDefaultMessageBundle().getString("observacao")); objectRoot.put("matricula", requerimento.getDiscente().getMatricula()); objectRoot.put("discente", requerimento.getDiscente().getNome()); objectRoot.put("tipoRequerimento", LocaleBean.getDefaultMessageBundle() .getString(requerimento.getTipoRequerimento().getTipo())); objectRoot.put("status", LocaleBean.getDefaultMessageBundle().getString(requerimento.getStatus().getStatus())); objectRoot.put("atendente", requerimento.getAtendimento().getAtendente().getNome()); objectRoot.put("observacao", requerimento.getAtendimento().getObservacao()); URL logo = new File(context.getRealPath("/resources/img/logo-mono-mini.png")).toURI().toURL(); Template template = templateConf.getTemplate("notificacao_discente.ftl"); Writer writer = new StringWriter(); HtmlEmail email = new HtmlEmail(); String logoId = email.embed(logo, "logo"); objectRoot.put("logo", logoId); template.process(objectRoot, writer); email.setHostName(configDao.getValue("mail.mailHost")); email.setSmtpPort(Integer.parseInt(configDao.getValue("mail.smtpPort"))); String mailSender = configDao.getValue("mail.mailSender"); String user = configDao.getValue("mail.mailUser"); String password = configDao.getValue("mail.mailPassword"); boolean useSSL = Boolean.parseBoolean(configDao.getValue("mail.useSSL")); email.setAuthenticator(new DefaultAuthenticator(user, password)); email.setSSLOnConnect(useSSL); email.setFrom(mailSender); email.addTo(requerimento.getDiscente().getEmail()); email.setSubject(LocaleBean.getDefaultMessageBundle().getString("subjectMail")); email.setHtmlMsg(writer.toString()); String alternativeMessage = String.format("%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s", LocaleBean.getDefaultMessageBundle().getString("messageMail"), objectRoot.get("REQUERIMENTO"), objectRoot.get("tipoRequerimento"), objectRoot.get("STATUS"), objectRoot.get("status"), objectRoot.get("ATENDENTE"), objectRoot.get("atendente"), objectRoot.get("OBSERVACAO"), objectRoot.get("observacao")); email.setTextMsg(alternativeMessage); email.send(); System.out.println(String.format("message to discente:<%s: %s>", requerimento.getDiscente().getNome(), requerimento.getDiscente().getEmail())); } catch (EmailException | IOException | TemplateException e) { System.out.println("erro ao enviar email"); System.out.println(e); } } }; sender.start(); }