List of usage examples for org.apache.commons.mail HtmlEmail addTo
public Email addTo(final String email) throws EmailException
From source file:edu.wright.cs.fa15.ceg3120.concon.server.EmailManager.java
/** * Add an outgoing email to the queue./*from w ww . j a v a 2 s . c o m*/ * @param to Array of email addresses. * @param subject Header * @param body Content * @param attachmentFile Attachment */ public void addEmail(String[] to, String subject, String body, File attachmentFile) { HtmlEmail mail = new HtmlEmail(); Properties sysProps = System.getProperties(); // Setup mail server sysProps.setProperty("mail.smtp.host", props.getProperty("mail_server_hostname")); Session session = Session.getDefaultInstance(sysProps); try { mail.setMailSession(session); mail.setFrom(props.getProperty("server_email_addr"), props.getProperty("server_title")); mail.addTo(to); mail.setSubject(subject); mail.setTextMsg(body); mail.setHtmlMsg(composeAsHtml(mail, body)); if (attachmentFile.exists()) { EmailAttachment attachment = new EmailAttachment(); attachment.setPath(attachmentFile.getPath()); mail.attach(attachment); } } catch (EmailException e) { LOG.warn("Email was not added. ", e); } mailQueue.add(mail); }
From source file:com.enseval.ttss.util.MailNotif.java
public void emailGiroTolak(Giro gironya, String namaCustomer, String customerID) { String port = (Executions.getCurrent().getServerPort() == 80) ? "" : (":" + Executions.getCurrent().getServerPort()); String url = Executions.getCurrent().getScheme() + "://" + Executions.getCurrent().getServerName() + port + Executions.getCurrent().getContextPath() + "/info_giro.zul"; String msg = "<html>" + "<head>" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" + "<title>Untitled Document</title>" + "<style type=\"text/css\">" + "p {" + "font-family: \"Courier New\", Courier, monospace;" + "font-size: 12px;" + "}" + "</style>" + "</head>" + "<p>Yth, </p>" + "<p>Berikut kami informasikan customer/outlet baru ditambahkan dalam daftar giro tolak;</p> " + "<br/>" + "<p><pre>" + "Customer ID : " + customerID + "<br/>" + "Nama Customer : " + namaCustomer + "<br/>" + "Nomor Giro : " + gironya.getNomorGiro() + "<br/>" + "Nilai : " + Rupiah.format(gironya.getNilai()) + "<br/>" + "Bank : " + gironya.getBank() + "<br/>" + "Keterangan : " + gironya.getKeterangan() + "" + "<pre>" + "</p>" + "<br/>" + "<br/>" + "<br/>" + "<p>Outlet akan di hold sementara oleh bagian Data Proses, selama di hold outlet tidak bisa melakukan order</p>" + "<br/>" + "<br/>" + "<p><i>Note : " + "<br>" + "Info giro " + url + "<br/>" + "Ini adalah email otomatis, mohon tidak membalas email ini !</i></p>" + "</html>"; try {/*from www . j a v a 2s. co m*/ HtmlEmail mail = new HtmlEmail(); mail.setHostName(Util.setting("smtp_host")); mail.setSmtpPort(Integer.parseInt(Util.setting("smtp_port"))); mail.setAuthenticator((Authenticator) new DefaultAuthenticator(Util.setting("smtp_username"), Util.setting("smtp_password"))); mail.setFrom(Util.setting("email_from")); for (String s : Util.setting("email_to").split(",")) { mail.addTo(s.trim()); } mail.setSubject("[INFO GIRO TOLAK] - Nomor Giro : " + gironya.getNomorGiro() + " , Customer : " + namaCustomer + " (" + customerID + ")"); mail.setHtmlMsg(msg); mail.send(); } catch (EmailException ex) { Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.enseval.ttss.util.MailNotif.java
public void emailTolakUpdate(Giro gironya) { String port = (Executions.getCurrent().getServerPort() == 80) ? "" : (":" + Executions.getCurrent().getServerPort()); String url = Executions.getCurrent().getScheme() + "://" + Executions.getCurrent().getServerName() + port + Executions.getCurrent().getContextPath() + "/info_giro.zul"; String msg = "<html>" + "<head>" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" + "<title>Untitled Document</title>" + "<style type=\"text/css\">" + "p {" + "font-family: \"Courier New\", Courier, monospace;" + "font-size: 12px;" + "}" + "</style>" + "</head>" + "<p>Yth, </p>" + "<p>Berikut kami informasikan giro tolakan berikut sudah di proses kliring ulang;</p> " + "<br/>" + "<p><pre>" + "Customer ID : " + gironya.getCustomer().getId() + "<br/>" + "Nama Customer : " + gironya.getCustomer().getNama() + "<br/>" + "Nomor Giro : " + gironya.getNomorGiro() + "<br/>" + "Nilai : " + Rupiah.format(gironya.getNilai()) + "<br/>" + "Bank : " + gironya.getBank() + "<br/>" + "Tgl Kliring : " + gironya.getTglKliring() + "<br/>" + "Keterangan : " + gironya.getKeterangan() + "" + "<pre>" + "</p>" + "<br/>" + "<br/>" + "<br/>" + "<p>Jika tidak ada tolakan, account shipto customer akan segera diaktifkan oleh bagian Data Proses.</p>" + "<br/>" + "<br/>" + "<p><i>Note : " + "<br>" + "Info giro " + url + "<br/>" + "Ini adalah email otomatis, mohon tidak membalas email ini !</i></p>" + "</html>"; try {/*w ww.j ava 2s . c o m*/ HtmlEmail mail = new HtmlEmail(); mail.setHostName(Util.setting("smtp_host")); mail.setSmtpPort(Integer.parseInt(Util.setting("smtp_port"))); mail.setAuthenticator((Authenticator) new DefaultAuthenticator(Util.setting("smtp_username"), Util.setting("smtp_password"))); mail.setFrom(Util.setting("email_from")); for (String s : Util.setting("email_to").split(",")) { mail.addTo(s.trim()); } mail.setSubject("[INFO GIRO TOLAK - Update] - Nomor Giro : " + gironya.getNomorGiro() + " , Customer : " + gironya.getCustomer().getNama() + " (" + gironya.getCustomer().getId() + ")"); mail.setHtmlMsg(msg); mail.send(); } catch (EmailException ex) { Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.hangum.tadpold.commons.libs.core.mails.SendEmails.java
/** * send email//from ww w .j a va 2 s . c o m * * @param emailDao */ public void sendMail(EmailDTO emailDao) throws Exception { if (logger.isDebugEnabled()) logger.debug("Add new message"); try { // MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap(); // mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html"); // mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml"); // mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain"); // mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed"); // mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822"); // CommandMap.setDefaultCommandMap(mc); HtmlEmail email = new HtmlEmail(); email.setHostName(smtpDto.getHost()); email.setSmtpPort(NumberUtils.toInt(smtpDto.getPort())); email.setAuthenticator(new DefaultAuthenticator(smtpDto.getEmail(), smtpDto.getPasswd())); email.setSSLOnConnect(true); email.setFrom(smtpDto.getEmail(), "Tadpole DB Hub"); email.setSubject(emailDao.getSubject()); // set the html message email.setHtmlMsg(emailDao.getContent()); email.addTo(emailDao.getTo()); email.send(); } catch (Exception e) { logger.error("send email", e); throw e; } }
From source file:enviocorreo.EnviadorCorreo.java
/** * Enva un correo electrnico. Utiliza la biblioteca Apache Commons Email, * accesible va <a href="https://commons.apache.org/proper/commons-email/">https://commons.apache.org/proper/commons-email/</a> * * @param destinatario// w w w .j ava 2 s . co m * @param asunto * @param mensaje * @return */ public boolean enviarCorreoE(String destinatario, String asunto, String mensaje) { boolean resultado = false; HtmlEmail email = new HtmlEmail(); email.setHostName(host); email.setSmtpPort(puerto); email.setAuthenticator(new DefaultAuthenticator(usuario, password)); if (isGmail) { email.setSSLOnConnect(true); } else { email.setStartTLSEnabled(true); } try { email.setFrom(usuario + "<dominio del correo>"); email.setSubject(asunto); email.setHtmlMsg(mensaje); email.addTo(destinatario); email.send(); resultado = true; } catch (EmailException eme) { mensaje = "Ocurri un error al hacer el envo de correo."; mensajeError = eme.toString(); } return resultado; }
From source file:br.com.mysqlmonitor.monitor.Monitor.java
private void enviarEmailDBA() { try {/*from w ww . j a v a 2s. co m*/ if (logs.length() != 0) { System.out.println("Divergencias: " + logs); for (Usuario usuario : usuarioDAO.findAll()) { System.out.println("Enviando email para: " + usuario.getNome()); HtmlEmail email = new HtmlEmail(); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator("mysqlmonitorsuporte", "4rgvr6RM")); email.setSSL(true); email.setFrom("mysqlmonitorsuporte@gmail.com"); email.setSubject("Log Mysql Monitor"); email.setHtmlMsg(logs.toString()); email.addTo(usuario.getEmail()); email.send(); } } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:br.com.asisprojetos.email.SendEmail.java
public void enviar(String toEmail[], String subject, String templateFile, List<String> fileNames, String mes, int codContrato) { try {/*from www .j av a 2s . c om*/ String htmlFileTemplate = loadHtmlFile(templateFile); for (String to : toEmail) { String htmlFile = htmlFileTemplate; // Create the email message HtmlEmail email = new HtmlEmail(); email.setHostName(config.getHostname()); email.setSmtpPort(config.getPort()); email.setFrom(config.getFrom(), config.getFromName()); // remetente email.setAuthenticator( new DefaultAuthenticator(config.getAuthenticatorUser(), config.getAuthenticatorPassword())); email.setSSL(true); email.setSubject(subject); //Assunto email.addTo(to);//para logger.debug("Enviando Email para : [{}] ", to); int i = 1; for (String fileName : fileNames) { String cid; if (fileName.startsWith("diagnostico")) { try { cid = email.embed(new File(String.format("%s/%s", config.getOutDirectory(), fileName))); htmlFile = StringUtils.replace(htmlFile, "$codGraph24$", "<img src=\"cid:" + cid + "\">"); } catch (EmailException ex) { logger.error("Arquivo de diagnostico nao encontrado."); } } else if (fileName.startsWith("recorrencia")) { try { cid = email.embed(new File(String.format("%s/%s", config.getOutDirectory(), fileName))); htmlFile = StringUtils.replace(htmlFile, "$codGraph25$", "<img src=\"cid:" + cid + "\">"); } catch (EmailException ex) { logger.error("Arquivo de recorrencia nao encontrado."); } } else { cid = email.embed(new File(String.format("%s/%s", config.getOutDirectory(), fileName))); htmlFile = StringUtils.replace(htmlFile, "$codGraph" + i + "$", "<img src=\"cid:" + cid + "\">"); i++; } } //apaga $codGraph$ no usado do template for (int t = i; t <= 25; t++) { htmlFile = StringUtils.replace(htmlFile, "$codGraph" + t + "$", " "); } htmlFile = StringUtils.replace(htmlFile, "$MES$", mes); htmlFile = StringUtils.replace(htmlFile, "$MAIL$", to); htmlFile = StringUtils.replace(htmlFile, "$CONTRATO$", Integer.toString(codContrato)); email.setHtmlMsg(htmlFile); // set the alternative message email.setTextMsg("Your email client does not support HTML messages"); // send the email email.send(); } logger.debug("Email enviado com sucesso......"); } catch (FileNotFoundException ex) { logger.error("Arquivo [{}/{}] nao encontrado para leitura.", config.getHtmlDirectory(), templateFile); } catch (Exception ex) { logger.error("Erro ao Enviar email : {}", ex); } }
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 ww w. j a v a 2s. c o 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.cerebro.provevaadin.smtp.ConfigurazioneSMTP.java
public ConfigurazioneSMTP() { this.setMargin(true); TextField smtpHost = new TextField("SMTP Host Server"); smtpHost.setRequired(true);//from w ww . j av a 2 s . c o m TextField smtpPort = new TextField("SMTP Port"); smtpPort.setRequired(true); TextField smtpUser = new TextField("SMTP Username"); smtpUser.setRequired(true); TextField smtpPwd = new TextField("SMTP Password"); smtpPwd.setRequired(true); TextField pwdConf = new TextField("Conferma la Password"); pwdConf.setRequired(true); CheckBox security = new CheckBox("Sicurezza del server"); Properties props = new Properties(); InputStream config = VaadinServlet.getCurrent().getServletContext() .getResourceAsStream("/WEB-INF/config.properties"); if (config != null) { System.out.println("Carico file di configurazione"); try { props.load(config); } catch (IOException ex) { Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex); } } smtpHost.setValue(props.getProperty("smtp_host")); smtpUser.setValue(props.getProperty("smtp_user")); security.setValue(Boolean.parseBoolean(props.getProperty("smtp_sec"))); Button salva = new Button("Salva i parametri"); salva.addClickListener((Button.ClickEvent event) -> { System.out.println("Salvo i parametri SMTP"); if (smtpHost.isValid() && smtpPort.isValid() && smtpUser.isValid() && smtpPwd.isValid() && smtpPwd.getValue().equals(pwdConf.getValue())) { props.setProperty("smtp_host", smtpHost.getValue()); props.setProperty("smtp_port", smtpPort.getValue()); props.setProperty("smtp_user", smtpUser.getValue()); props.setProperty("smtp_pwd", smtpPwd.getValue()); props.setProperty("smtp_sec", security.getValue().toString()); String webInfPath = VaadinServlet.getCurrent().getServletConfig().getServletContext() .getRealPath("WEB-INF"); File f = new File(webInfPath + "/config.properties"); try { OutputStream o = new FileOutputStream(f); try { props.store(o, "Prova"); } catch (IOException ex) { Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex); } Notification.show("Parametri salvati"); } else { Notification.show("Ricontrolla i parametri"); } }); TextField emailTest = new TextField("Destinatario Mail di Prova"); emailTest.setImmediate(true); emailTest.addValidator(new EmailValidator("Mail non valida")); Button test = new Button("Invia una mail di prova"); test.addClickListener((Button.ClickEvent event) -> { System.out.println("Invio della mail di prova"); if (emailTest.isValid()) { try { System.out.println("Invio mail di prova a " + emailTest.getValue()); HtmlEmail email = new HtmlEmail(); email.setHostName(props.getProperty("smtp_host")); email.setSmtpPort(Integer.parseInt(props.getProperty("smtp_port"))); email.setSSLOnConnect(Boolean.parseBoolean(props.getProperty("smtp_sec"))); email.setAuthentication(props.getProperty("smtp_user"), props.getProperty("smtp_pwd")); email.setFrom("prova@prova.it"); email.setSubject("Mail di prova"); email.addTo(emailTest.getValue()); email.setHtmlMsg("This is the message"); email.send(); } catch (EmailException ex) { Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex); } } else { Notification.show("Controlla l'indirizzo mail del destinatario"); } }); this.addComponents(smtpHost, smtpPort, smtpUser, smtpPwd, pwdConf, security, salva, emailTest, test); }
From source file:com.duroty.application.mail.manager.SendManager.java
/** * DOCUMENT ME!/*ww w . java2 s . c o m*/ * * @param session DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param from DOCUMENT ME! * @param to DOCUMENT ME! * @param subject DOCUMENT ME! * @param body DOCUMENT ME! * * @throws MailException DOCUMENT ME! */ public void sendIdentity(Session session, String repositoryName, String from, String to, String subject, String body) throws MailException { try { HtmlEmail email = new HtmlEmail(); email.setMailSession(session); email.setFrom(from); email.addTo(to); email.setSubject(subject); email.setHtmlMsg(body); email.setCharset(Charset.defaultCharset().displayName()); email.send(); } catch (Exception e) { throw new MailException(e); } finally { } }