List of usage examples for org.apache.commons.mail HtmlEmail addTo
public Email addTo(final String email, final String name) throws EmailException
From source file:br.com.itfox.utils.SendHtmlFormatedEmail.java
public void sendingHtml(String orderDetails, String orderNumber, String toName, String toEmail) { try {//from w w w.j av a2s . co 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: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 ww. ja v a2s . 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:com.esofthead.mycollab.module.mail.DefaultMailer.java
private HtmlEmail getBasicEmail(String fromEmail, String fromName, List<MailRecipientField> toEmail, List<MailRecipientField> ccEmail, List<MailRecipientField> bccEmail, String subject, String html) { try {//from w ww .jav a2 s . com HtmlEmail email = new HtmlEmail(); email.setHostName(host); email.setFrom(fromEmail, fromName); email.setCharset(EmailConstants.UTF_8); for (int i = 0; i < toEmail.size(); i++) { if (isValidate(toEmail.get(i).getEmail()) && isValidate(toEmail.get(i).getName())) { email.addTo(toEmail.get(i).getEmail(), toEmail.get(i).getName()); } else { LOG.error("Invalid to email input: " + toEmail.get(i).getEmail() + "---" + toEmail.get(i).getName()); } } if (CollectionUtils.isNotEmpty(ccEmail)) { for (int i = 0; i < ccEmail.size(); i++) { if (isValidate(ccEmail.get(i).getEmail()) && isValidate(ccEmail.get(i).getName())) { email.addCc(ccEmail.get(i).getEmail(), ccEmail.get(i).getName()); } else { LOG.error("Invalid cc email input: " + ccEmail.get(i).getEmail() + "---" + ccEmail.get(i).getName()); } } } if (CollectionUtils.isNotEmpty(bccEmail)) { for (int i = 0; i < bccEmail.size(); i++) { if (isValidate(bccEmail.get(i).getEmail()) && isValidate(bccEmail.get(i).getName())) { email.addBcc(bccEmail.get(i).getEmail(), bccEmail.get(i).getName()); } else { LOG.error("Invalid bcc email input: " + bccEmail.get(i).getEmail() + "---" + bccEmail.get(i).getName()); } } } if (username != null) { email.setAuthentication(username, password); } email.setStartTLSEnabled(isTLS); email.setSubject(subject); if (StringUtils.isNotBlank(html)) { email.setHtmlMsg(html); } return email; } catch (EmailException e) { throw new MyCollabException(e); } }
From source file:br.com.itfox.beans.SendHtmlFormatedEmail.java
public void sendingHtml() { try {//from w ww . j av a 2 s.co m // 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.itfox.beans.SendHtmlFormatedEmail.java
public void sendingHtml(String destinatario, String nome, String assunto, URL linkBoleto) { try {//from ww w . ja va 2 s . co m // 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:br.com.itfox.beans.SendHtmlFormatedEmail.java
/** * * @param destinatario// ww w .j a va 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.mycollab.module.mail.DefaultMailer.java
private HtmlEmail getBasicEmail(String fromEmail, String fromName, List<MailRecipientField> toEmail, List<MailRecipientField> ccEmail, List<MailRecipientField> bccEmail, String subject, String html) { try {// w ww . j a v a 2 s.c o m HtmlEmail email = new HtmlEmail(); email.setHostName(emailConf.getHost()); email.setSmtpPort(emailConf.getPort()); email.setStartTLSEnabled(emailConf.getIsStartTls()); email.setSSLOnConnect(emailConf.getIsSsl()); email.setFrom(fromEmail, fromName); email.setCharset(EmailConstants.UTF_8); for (MailRecipientField aToEmail : toEmail) { if (isValidate(aToEmail.getEmail()) && isValidate(aToEmail.getName())) { email.addTo(aToEmail.getEmail(), aToEmail.getName()); } else { LOG.error(String.format("Invalid to email input: %s---%s", aToEmail.getEmail(), aToEmail.getName())); } } if (CollectionUtils.isNotEmpty(ccEmail)) { for (MailRecipientField aCcEmail : ccEmail) { if (isValidate(aCcEmail.getEmail()) && isValidate(aCcEmail.getName())) { email.addCc(aCcEmail.getEmail(), aCcEmail.getName()); } else { LOG.error(String.format("Invalid cc email input: %s---%s", aCcEmail.getEmail(), aCcEmail.getName())); } } } if (CollectionUtils.isNotEmpty(bccEmail)) { for (MailRecipientField aBccEmail : bccEmail) { if (isValidate(aBccEmail.getEmail()) && isValidate(aBccEmail.getName())) { email.addBcc(aBccEmail.getEmail(), aBccEmail.getName()); } else { LOG.error(String.format("Invalid bcc email input: %s---%s", aBccEmail.getEmail(), aBccEmail.getName())); } } } if (emailConf.getUser() != null) { email.setAuthentication(emailConf.getUser(), emailConf.getPassword()); } email.setSubject(subject); if (StringUtils.isNotBlank(html)) { email.setHtmlMsg(html); } return email; } catch (EmailException e) { throw new MyCollabException(e); } }
From source file:br.com.hslife.imobiliaria.service.EmailService.java
/** * Envia email no formato HTML/*from w w w . ja v a 2s . c om*/ * * @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(); }
From source file:br.com.hslife.catu.service.EmailService.java
/** * Envia email no formato HTML/*from www. j a va 2 s .c o 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.setCharset("UTF8"); //email.setSmtpPort(465); //email.setSSL(true); //email.setTLS(true); // envia email email.send(); }
From source file:controllers.ProjectApp.java
private static void sendTransferRequestMail(ProjectTransfer pt) { HtmlEmail email = new HtmlEmail(); try {/*from w w w .j a v a2s. c o m*/ String acceptUrl = pt.getAcceptUrl(); String message = Messages.get("transfer.message.hello", pt.destination) + "\n\n" + Messages.get("transfer.message.detail", pt.project.name, pt.newProjectName, pt.project.owner, pt.destination) + "\n" + Messages.get("transfer.message.link") + "\n\n" + acceptUrl + "\n\n" + Messages.get("transfer.message.deadline") + "\n\n" + Messages.get("transfer.message.thank"); email.setFrom(Config.getEmailFromSmtp(), pt.sender.name); email.addTo(Config.getEmailFromSmtp(), "Yobi"); User to = User.findByLoginId(pt.destination); if (!to.isAnonymous()) { email.addBcc(to.email, to.name); } Organization org = Organization.findByName(pt.destination); if (org != null) { List<OrganizationUser> admins = OrganizationUser.findAdminsOf(org); for (OrganizationUser admin : admins) { email.addBcc(admin.user.email, admin.user.name); } } email.setSubject( String.format("[%s] @%s wants to transfer project", pt.project.name, pt.sender.loginId)); email.setHtmlMsg(Markdown.render(message)); email.setTextMsg(message); email.setCharset("utf-8"); email.addHeader("References", "<" + acceptUrl + "@" + Config.getHostname() + ">"); email.setSentDate(pt.requested); Mailer.send(email); String escapedTitle = email.getSubject().replace("\"", "\\\""); String logEntry = String.format("\"%s\" %s", escapedTitle, email.getBccAddresses()); play.Logger.of("mail").info(logEntry); } catch (Exception e) { Logger.warn("Failed to send a notification: " + email + "\n" + ExceptionUtils.getStackTrace(e)); } }