List of usage examples for org.apache.commons.mail HtmlEmail HtmlEmail
HtmlEmail
From source file:com.kylinolap.common.util.MailService.java
/** * //from ww w . j av a 2 s.co m * @param receivers * @param subject * @param content * @return true or false indicating whether the email was delivered successfully * @throws IOException */ public boolean sendMail(List<String> receivers, String subject, String content) throws IOException { if (!enabled) { logger.info("Email service is disabled; this mail will not be delivered: " + subject); logger.info("To enable mail service, set 'mail.enabled=true' in kylin.properties"); return false; } Email email = new HtmlEmail(); email.setHostName(host); if (username != null && username.trim().length() > 0) { email.setAuthentication(username, password); } //email.setDebug(true); try { for (String receiver : receivers) { email.addTo(receiver); } email.setFrom(sender); email.setSubject(subject); email.setCharset("UTF-8"); ((HtmlEmail) email).setHtmlMsg(content); email.send(); email.getMailSession(); } catch (EmailException e) { logger.error(e.getLocalizedMessage(), e); return false; } return true; }
From source file:dk.dma.ais.abnormal.analyzer.reports.ReportMailer.java
/** * Send email with subject and message body. * @param subject the email subject.//from ww w. j av a 2s . c o m * @param body the email body. */ public void send(String subject, String body) { try { HtmlEmail email = new HtmlEmail(); email.setHostName(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_HOST, "localhost")); email.setSmtpPort(configuration.getInt(CONFKEY_REPORTS_MAILER_SMTP_PORT, 465)); email.setAuthenticator( new DefaultAuthenticator(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_USER, "anonymous"), configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_PASS, "guest"))); email.setStartTLSEnabled(false); email.setSSLOnConnect(configuration.getBoolean(CONFKEY_REPORTS_MAILER_SMTP_SSL, true)); email.setFrom(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_FROM, "")); email.setSubject(subject); email.setHtmlMsg(body); String[] receivers = configuration.getStringArray(CONFKEY_REPORTS_MAILER_SMTP_TO); for (String receiver : receivers) { email.addTo(receiver); } email.send(); LOG.info("Report sent with email to " + email.getToAddresses().toString() + " (\"" + subject + "\")"); } catch (EmailException e) { LOG.error(e.getMessage(), e); } }
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 w ww . j av a2 s . c om 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: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());//from w ww. j a v a 2 s . co m 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:Email.CommonsEmail.java
/** * funo para enviar email/* w w w . j a va 2s . c om*/ * * @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:FacultyAdvisement.ImagineBean.java
public String submitRequest() { String emailCourses = ""; for (Course c : currentCourses) { emailCourses += "<li>" + c.getSubject() + " " + c.getNumber() + "</li>"; }/*from w w w. j a v a 2 s . c om*/ try { Email email = new HtmlEmail(); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator("uco.faculty.advisement", "!@#$1234")); email.setSSLOnConnect(true); email.setFrom("uco.faculty.advisement@gmail.com"); email.setSubject("Microsoft Imagine Account"); email.setMsg("<font size=\"3\" style=\"font-family:verdana\"> \n" + "<ul><li>Student Name: " + student.getFirstName() + " " + student.getLastName() + "</li><li>Student Major: " + student.getMajorCode() + "<li>Current Courses: <ol>" + emailCourses + "</ol></li></ul> " + "Student Email if needed for response: " + student.getUsername() + "\n<p align=\"center\">UCO Faculty Advisement</p></font>"); email.addTo("uco.faculty.advisement@gmail.com"); email.send(); } catch (EmailException ex) { Logger.getLogger(VerificationBean.class.getName()).log(Level.SEVERE, null, ex); } return "/customerFolder/imagineConfirm"; }
From source file:br.com.itfox.beans.SendHtmlFormatedEmail.java
public void sendingHtml() { try {/*ww w. ja v a 2 s . com*/ // 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("belchiorpalma@gmail.com", "Belchior Palma"); //email.setFrom("belchiorpalma@me.com", "Me"); email.setSubject("Test email with inline image"); email.setSubject(MimeUtility.encodeText("Test email with inline image", "UTF-8", "B")); // 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"); // set the html message email.setHtmlMsg("<html>The apache logo - <img src=\"cid:" + cid + "\"></html>"); // 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); } catch (MalformedURLException ex) { Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:br.com.atmatech.sac.controller.Email.java
public void emaiMassa(String smtp, String user, String password, Integer porta, Boolean ssl, Boolean tls, List<PessoaBeans> emailto, String emailfrom, String conteudo, String assunto) throws EmailException, MalformedURLException { HtmlEmail email = new HtmlEmail(); email.setHostName(smtp); // o servidor SMTP para envio do e-mail Integer indice2 = 0;//from ww w . jav a 2s. c om Integer j = 0; for (int i = 0; (i < emailto.size()) && (i < 45); i++) { email.addTo(emailto.get(i).getEmail());//destinatario indice2 = i; } while (j <= indice2) { emailto.remove(0); j++; } conteudo = conteudo.replaceAll("\n", "<p>"); email.setFrom(emailfrom); // remetente //email.addCc(emailfrom); email.setSubject(assunto); // configura a mensagem para o formato HTML email.setHtmlMsg("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">" + conteudo + "</html>"); email.setAuthentication(user, password); email.setSmtpPort(porta); email.setSSL(ssl); email.setTLS(tls); email.send(); if (emailto != null) { if (emailto.size() > 1) { emaiMassa(smtp, user, password, porta, ssl, tls, emailto, emailfrom, conteudo, assunto); } } }
From source file:com.mirth.connect.connectors.smtp.SmtpMessageDispatcher.java
@Override public void doDispatch(UMOEvent event) throws Exception { monitoringController.updateStatus(connector, connectorType, Event.BUSY); MessageObject mo = messageObjectController.getMessageObjectFromEvent(event); if (mo == null) { return;//w w w.j av a 2 s . com } try { Email email = null; if (connector.isHtml()) { email = new HtmlEmail(); } else { email = new MultiPartEmail(); } email.setCharset(connector.getCharsetEncoding()); email.setHostName(replacer.replaceValues(connector.getSmtpHost(), mo)); try { email.setSmtpPort(Integer.parseInt(replacer.replaceValues(connector.getSmtpPort(), mo))); } catch (NumberFormatException e) { // Don't set if the value is invalid } try { email.setSocketConnectionTimeout( Integer.parseInt(replacer.replaceValues(connector.getTimeout(), mo))); } catch (NumberFormatException e) { // Don't set if the value is invalid } if ("SSL".equalsIgnoreCase(connector.getEncryption())) { email.setSSL(true); } else if ("TLS".equalsIgnoreCase(connector.getEncryption())) { email.setTLS(true); } if (connector.isAuthentication()) { email.setAuthentication(replacer.replaceValues(connector.getUsername(), mo), replacer.replaceValues(connector.getPassword(), mo)); } /* * NOTE: There seems to be a bug when calling setTo with a List * (throws a java.lang.ArrayStoreException), so we are using addTo * instead. */ for (String to : replaceValuesAndSplit(connector.getTo(), mo)) { email.addTo(to); } // Currently unused for (String cc : replaceValuesAndSplit(connector.cc(), mo)) { email.addCc(cc); } // Currently unused for (String bcc : replaceValuesAndSplit(connector.getBcc(), mo)) { email.addBcc(bcc); } // Currently unused for (String replyTo : replaceValuesAndSplit(connector.getReplyTo(), mo)) { email.addReplyTo(replyTo); } for (Entry<String, String> header : connector.getHeaders().entrySet()) { email.addHeader(replacer.replaceValues(header.getKey(), mo), replacer.replaceValues(header.getValue(), mo)); } email.setFrom(replacer.replaceValues(connector.getFrom(), mo)); email.setSubject(replacer.replaceValues(connector.getSubject(), mo)); String body = replacer.replaceValues(connector.getBody(), mo); if (connector.isHtml()) { ((HtmlEmail) email).setHtmlMsg(body); } else { email.setMsg(body); } /* * If the MIME type for the attachment is missing, we display a * warning and set the content anyway. If the MIME type is of type * "text" or "application/xml", then we add the content. If it is * anything else, we assume it should be Base64 decoded first. */ for (Attachment attachment : connector.getAttachments()) { String name = replacer.replaceValues(attachment.getName(), mo); String mimeType = replacer.replaceValues(attachment.getMimeType(), mo); String content = replacer.replaceValues(attachment.getContent(), mo); byte[] bytes; if (StringUtils.indexOf(mimeType, "/") < 0) { logger.warn("valid MIME type is missing for email attachment: \"" + name + "\", using default of text/plain"); attachment.setMimeType("text/plain"); bytes = content.getBytes(); } else if ("application/xml".equalsIgnoreCase(mimeType) || StringUtils.startsWith(mimeType, "text/")) { logger.debug("text or XML MIME type detected for attachment \"" + name + "\""); bytes = content.getBytes(); } else { logger.debug("binary MIME type detected for attachment \"" + name + "\", performing Base64 decoding"); bytes = Base64.decodeBase64(content); } ((MultiPartEmail) email).attach(new ByteArrayDataSource(bytes, mimeType), name, null); } /* * From the Commons Email JavaDoc: send returns * "the message id of the underlying MimeMessage". */ String response = email.send(); messageObjectController.setSuccess(mo, response, null); } catch (EmailException e) { alertController.sendAlerts(connector.getChannelId(), Constants.ERROR_402, "Error sending email message.", e); messageObjectController.setError(mo, Constants.ERROR_402, "Error sending email message.", e, null); connector.handleException(new Exception(e)); } finally { monitoringController.updateStatus(connector, connectorType, Event.DONE); } }
From source file:com.music.service.EmailService.java
private Email createEmail(boolean html) { Email e = null;//from w w w . ja v a 2 s .c o m if (html) { e = new HtmlEmail(); } else { e = new SimpleEmail(); } e.setHostName(smtpHost); if (!StringUtils.isEmpty(smtpUser)) { e.setAuthentication(smtpUser, smtpPassword); } if (!StringUtils.isEmpty(smtpBounceEmail)) { e.setBounceAddress(smtpBounceEmail); } e.setTLS(true); e.setSmtpPort(587); //tls port e.setCharset("UTF8"); //e.setDebug(true); return e; }