List of usage examples for org.apache.commons.mail HtmlEmail setSubject
public Email setSubject(final String aSubject)
From source file:br.com.mysqlmonitor.monitor.Monitor.java
private void enviarEmailDBA() { try {//w ww .j ava 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.itfox.beans.SendHtmlFormatedEmail.java
public void sendingHtml(String destinatario, String nome, String assunto, URL linkBoleto) { try {//from w w w . j a v a 2s . c om // Create the email message HtmlEmail email = new HtmlEmail(); email.setHostName("mail.congressotrt15.com.br"); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator("congresso@congressotrt15.com.br", "admtrt15xx")); email.setSSLOnConnect(false); //email.setTLS(true); email.setFrom("congresso@congressotrt15.com.br"); email.setSubject("TestMail"); email.addTo(destinatario, nome); //email.setFrom("belchiorpalma@me.com", "Me"); email.setSubject(assunto); email.setSubject(MimeUtility.encodeText(assunto, "UTF-8", "B")); // embed the image and get the content id URL url = linkBoleto;//new URL(linkBoleto); String cid = email.embed(url, new BusinessDelegate().getMensagem(new BigDecimal(61)).getAssunto()); // localizando a mensagem //Mensagem msg = new Mensagem(); //msg = new BusinessDelegate().getMensagem(mensagemId); // set the html message //email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"+cid+"\"></html>"); String body = ""; body += this.htmlHead; body += (this.bodyProfissional); body += ("Faça Download do Boleto para pagamento: - <a href=" + url + " target=\"_blank\">Clique Aqui para baixar o Boleto.</a>"); body += "<img src=\"cid:" + cid + "\">"; body += ("</body></html>"); //email.setContent(body,CONTENT_TYPE); email.setHtmlMsg(body); //email.setHeaders(null); //email.setHtmlMsg(body); // set the alternative message email.setTextMsg("Your email client does not support HTML messages"); // send the email email.send(); } catch (EmailException ex) { Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedEncodingException ex) { Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.wright.cs.fa15.ceg3120.concon.server.EmailManager.java
/** * Add an outgoing email to the queue./*from w w w .j a v a2s . 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.jredrain.service.NoticeService.java
public void sendMessage(Long receiverId, Long workId, String emailAddress, String mobiles, String content) { Log log = new Log(); log.setIsread(0);//ww w . jav a2 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: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/*from ww w . j a v a 2s . c o 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:de.hybris.platform.lichextendtrail.emailservice.DefaultLichEmailService.java
@Override public boolean send(EmailMessageModel message) { if (message == null) { throw new IllegalArgumentException("message must not be null"); }/* ww w . ja v a 2 s . c om*/ final boolean sendEnabled = getConfigurationService().getConfiguration() .getBoolean(EMAILSERVICE_SEND_ENABLED_CONFIG_KEY, true); if (sendEnabled) { try { final HtmlEmail email = getPerConfiguredEmail(); email.setCharset("UTF-8"); final List<EmailAddressModel> toAddresses = message.getToAddresses(); setAddresses(message, email, toAddresses); final EmailAddressModel fromAddress = message.getFromAddress(); email.setFrom(fromAddress.getEmailAddress(), nullifyEmpty(fromAddress.getDisplayName())); addReplyTo(message, email); email.setSubject(message.getSubject()); //??? if (message.getSubject().equals("?Customer Registration\n")) { email.setSubject("?"); //?? String emailToAddress = email.getToAddresses().get(0).toString(); emailToAddress = emailToAddress.substring(emailToAddress.indexOf('<') + 1, emailToAddress.indexOf('>')); // email.setHtmlMsg(LichValue.getEmailContent(emailToAddress)); } //??? else { email.setHtmlMsg(getBody(message)); } // To support plain text parts use email.setTextMsg() final List<EmailAttachmentModel> attachments = message.getAttachments(); if (!processAttachmentsSuccessful(email, attachments)) { return false; } // Important to log all emails sent out LOG.info("Sending Email [" + message.getPk() + "] To [" + convertToStrings(toAddresses) + "] From [" + fromAddress.getEmailAddress() + "] Subject [" + email.getSubject() + "]"); // Send the email and capture the message ID final String messageID = email.send(); message.setSent(true); message.setSentMessageID(messageID); message.setSentDate(new Date()); getModelService().save(message); return true; } catch (final EmailException e) { logInfo(message, e); } } else { LOG.warn("Could not send e-mail pk [" + message.getPk() + "] subject [" + message.getSubject() + "]"); LOG.info("Email sending has been disabled. Check the config property 'emailservice.send.enabled'"); return true; } return false; }
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 {//w ww. j a v a2 s .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] - 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 {/*from w w w . j a v a2 s.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:br.com.ezequieljuliano.argos.util.SendMail.java
public void send() throws EmailException { HtmlEmail email = new HtmlEmail(); email.setHostName(server.getHostName()); email.setAuthentication(server.getUser(), server.getPassWord()); email.setSSL(server.isSSL());// w w w . j a va 2 s.c om email.setSmtpPort(server.getPort()); for (Involved involved : recipients) { email.addTo(involved.getEmail(), involved.getName()); } email.setFrom(sender.getEmail(), sender.getName()); email.setSubject(subject); email.setHtmlMsg(message); email.setCharset("UTF-8"); EmailAttachment att; for (Attachment annex : attachment) { att = new EmailAttachment(); att.setPath(annex.getPath()); att.setDisposition(EmailAttachment.ATTACHMENT); att.setDescription(annex.getDescription()); att.setName(annex.getName()); email.attach(att); } email.send(); }
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 w ww . jav a 2 s . c o m 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); } }