List of usage examples for org.apache.commons.mail HtmlEmail setSubject
public Email setSubject(final String aSubject)
From source file:br.com.itfox.utils.SendHtmlFormatedEmail.java
public void sendingHtml(String orderDetails, String orderNumber, String toName, String toEmail) { try {// ww w . j av a 2 s .c o m // Create the email message HtmlEmail email = new HtmlEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator("belchiorpalma@gmail.com", "xp2002b5")); email.setSSLOnConnect(true); email.setTLS(true); email.setFrom("contato@itfox.com.br"); //email.setSubject("TestMail"); email.addTo(toEmail, toName); //email.setFrom("belchiorpalma@me.com", "Me"); //email.setSubject("Test email with inline image"); email.setSubject(MimeUtility.encodeText("Thank you for your order", "UTF-8", "B")); // embed the image and get the content id //URL url = new URL("http://boutiquecellars.com/img/white-wines.jpg"); //String cid = email.embed(url, "BoutiqueCellars.com"); // set the html message email.setHtmlMsg("Thank you for your order\n<br/><br/>" + "\n" + "We received your order #" + orderNumber + " and we are working on it now.\n<br/>" + "We will e-mail you an update as soon as your order is processed.\n<br/>" + "\n<br/>" + "Boutique Cellars team\n" + "\n<br/><br/><img src='http://boutiquecellars.com/img/logoemail.jpg'/> \n" + //orderDetails + "<br/><br/>BOUTIQUE CELLARS SUPPORTS THE RESPONSIBLE SERVICE OF ALCOHOL. NSW: UNDER THE LIQUOR\n<br/>" + "ACT 2007 IT IS AGAINST THE LAW TO SELL OR SUPPLY ALCOHOL TO, OR TO OBTAIN ALCOHOL ON\n<br/>" + "BEHALF OF, A PERSON UNDER THE AGE OF 18 YEARS. NSW PACKAGED LIQUOR LICENCE NUMBER\n<br/>" + "LIQP770016947. YOUR CONTRACT OF SALE IS WITH THE RELEVANT LICENSEE AT THE RELEVANT\n<br/>" + "PREMISES FROM WHICH YOU ORDER IS ACCEPTED AND FULFILLED. LIQUOR IS SOLD FROM OUR\n<br/>" + "PLATFORM ON BEHALF OF THE RELEVANT LICENSEE. ACCORDINGLY, YOUR OFFER TO PURCHASE IS\n<br/>" + "SUBJECT TO ACCEPTANCE OF YOUR OFFER BY THE HOLDER OF THE LIQUOR LICENCE, CERTIFICATION\n<br/>" + "AND EVIDENCE OF YOU BEING OVER 18 YEARS OF AGE, THE AVAILABILITY OF STOCK AND THE\n<br/>" + "LIQUOR WHICH IS THE SUBJECT MATTER OF YOUR OFFER BEING ASCERTAINED AND APPROPRIATED\n<br/>" + "AT THE ABOVE MENTIONED LICENSED PREMISES.<br/><br/>" + " Boutique Cellar Imports Pty Ltd | ABN 69 607 265 618"); // set the alternative message email.setTextMsg( "Thank you for your order, We received your order #18765 and we are working on it now.\n" + "We will e-mail you an update as soon as your order is processed.\n" + "\n" + "Boutique Cellars team"); // 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:com.cerebro.provevaadin.smtp.ConfigurazioneSMTP.java
public ConfigurazioneSMTP() { this.setMargin(true); TextField smtpHost = new TextField("SMTP Host Server"); smtpHost.setRequired(true);//from w w w. jav a 2 s . c om 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: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 w w w .j a v a2 s .com 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.itcs.commons.email.impl.RunnableSendHTMLEmail.java
public void run() { Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.INFO, "executing Asynchronous task RunnableSendHTMLEmail"); try {/* w w w . ja v a2 s . co m*/ HtmlEmail email = new HtmlEmail(); email.setCharset("utf-8"); email.setMailSession(getSession()); for (String dir : to) { email.addTo(dir); } if (cc != null) { for (String ccEmail : cc) { email.addCc(ccEmail); } } if (cco != null) { for (String ccoEmail : cco) { email.addBcc(ccoEmail); } } email.setSubject(subject); // set the html message email.setHtmlMsg(body); email.setFrom(getSession().getProperties().getProperty(Email.MAIL_SMTP_FROM, Email.MAIL_SMTP_USER), getSession().getProperties().getProperty(Email.MAIL_SMTP_FROMNAME, Email.MAIL_SMTP_USER)); // set the alternative message email.setTextMsg("Si ve este mensaje, significa que su cliente de correo no permite mensajes HTML."); // send the email if (attachments != null) { addAttachments(email, attachments); } email.send(); Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.INFO, "Email sent successfully to:{0} cc:{1} bcc:{2}", new Object[] { Arrays.toString(to), Arrays.toString(cc), Arrays.toString(cco) }); } catch (EmailException e) { Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.SEVERE, "EmailException Error sending email... with properties:\n" + session.getProperties(), e); } }
From source file:br.com.itfox.beans.SendHtmlFormatedEmail.java
/** * * @param destinatario/* w ww .j a v a 2 s. c o m*/ * @param nome * @param assunto * @throws IOException */ public void sendingHtml(String destinatario, String nome, String assunto, int tipoId) throws IOException { try { // 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, "Congresso TRT 15"); // set the html message //email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"+cid+"\"></html>"); String body = ""; body += this.htmlHead; if (tipoId == 1) { body += (this.bodyProfissional); } else if (tipoId == 2) { body += (this.bodyServidor); } else if (tipoId == 3) { body += (this.bodyMagistrado); } else if (tipoId == 4) { body += (this.bodyEstudante); } else { body += "Congresso TRT"; } // body+=("Faa 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(CONTENT_TYPE); //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) { // utils.Logger.getLogger("Erro ao enviar Email. "+tipoId+" - "+ex.toString(),tipoId); // utils.Logger.getLoggerPessoaFisica("Erro ao enviar email - sending html:"+ex.getMessage()); } }
From source file:com.zxy.commons.email.MailMessageUtils.java
/** * smtp??// www .j a v a 2 s.co m * * @param subject subject * @param htmlBody htmlBody * @param properties properties * @param from from * @param toList toList * @param ccList ccList * @param bccList bccList * @param embedUrls * @throws EmailException EmailException */ @SuppressWarnings({ "PMD.AvoidInstantiatingObjectsInLoops", "PMD.UseStringBufferForStringAppends" }) public static void sendMail(String subject, String htmlBody, Map<String, String> properties, String from, List<String> toList, List<String> ccList, List<String> bccList, Map<String, URL> embedUrls) throws EmailException { HtmlEmail htmlEmail = getEmail(); // from? if (!Strings.isNullOrEmpty(from)) { Address fromMailbox = parseMailbox(from); if (fromMailbox != null && StringUtils.isNotBlank(from)) { htmlEmail.setFrom(fromMailbox.getAddress(), fromMailbox.getName()); } } // to? if (toList != null && !toList.isEmpty()) { for (String to : toList) { if (StringUtils.isNotBlank(to)) { Address toMailbox = parseMailbox(to); htmlEmail.addTo(toMailbox.getAddress(), toMailbox.getName()); } } } // cc? if (ccList != null && !ccList.isEmpty()) { for (String cc : ccList) { if (StringUtils.isNotBlank(cc)) { Address ccMailbox = parseMailbox(cc); htmlEmail.addCc(ccMailbox.getAddress(), ccMailbox.getName()); } } } // bcc? if (bccList != null && !bccList.isEmpty()) { for (String bcc : bccList) { if (StringUtils.isNotBlank(bcc)) { Address bccMailbox = parseMailbox(bcc); htmlEmail.addBcc(bccMailbox.getAddress(), bccMailbox.getName()); } } } // htmlEmail.setSubject(subject); htmlEmail.setHtmlMsg(htmlBody); htmlEmail.setSentDate(new Date()); // if (properties != null) { htmlEmail.setHeaders(properties); } // if (embedUrls != null && !embedUrls.isEmpty()) { for (Map.Entry<String, URL> entry : embedUrls.entrySet()) { String cid = entry.getKey(); URL url = entry.getValue(); String fileName = StringUtils.substringAfterLast(url.getPath(), "/"); if (StringUtils.isBlank(fileName)) { fileName = cid; } else { fileName += IdUtils.genStringId(); } htmlEmail.embed(new URLDataSource(url), fileName, cid); } } htmlEmail.send(); }
From source file:dk.dma.ais.abnormal.analyzer.reports.ReportMailer.java
/** * Send email with subject and message body. * @param subject the email subject.//from w w w.jav 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.duroty.application.mail.manager.SendManager.java
/** * DOCUMENT ME!//w ww . ja v a 2 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 { } }
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++;/* www . j a v a 2 s.c om*/ } 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:br.com.hslife.imobiliaria.service.EmailService.java
/** * Envia email no formato HTML/*from www. jav a 2 s . co m*/ * * @param nomeRemetente * @param nomeDestinatario * @param emailRemetente * @param emailDestinatario * @param assunto * @param mensagem * @param anexo * * @throws EmailException * @throws MalformedURLException */ public void enviaEmailFormatoHtml(String nomeRementente, String emailRemetente, String nomeDestinatario, String emailDestinatario, String assunto, StringBuilder mensagem, String anexo) throws EmailException, MalformedURLException { HtmlEmail email = new HtmlEmail(); // adiciona uma imagem ao corpo da mensagem e retorna seu id URL url = new URL(anexo); // URL do arquivo a ser anexado String cid = email.embed(url, "Anexos"); // configura a mensagem para o formato HTML email.setHtmlMsg("<html>Anexos</html>"); // configure uma mensagem alternativa caso o servidor no suporte HTML email.setTextMsg("Seu servidor de e-mail no suporta mensagem HTML"); email.setHostName("smtp.hslife.com.br"); // o servidor SMTP para envio do e-mail email.addTo(emailDestinatario, nomeDestinatario); //destinatrio email.setFrom(emailRemetente, nomeRementente); // remetente email.setSubject(assunto); // assunto do e-mail email.setMsg(mensagem.toString()); //conteudo do e-mail email.setAuthentication("realimoveis@hslife.com.br", "real123"); //email.setSmtpPort(465); //email.setSSL(true); //email.setTLS(true); // envia email email.send(); }