List of usage examples for org.apache.commons.mail HtmlEmail setHtmlMsg
public HtmlEmail setHtmlMsg(final String aHtml) 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. java 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:br.com.itfox.beans.SendHtmlFormatedEmail.java
public void sendingHtml() { try {//w w w .j a va 2 s .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("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:com.flagleader.builder.dialogs.s.java
protected void okPressed() { try {// w ww .jav a 2s . c o m HtmlEmail localHtmlEmail = new HtmlEmail(); localHtmlEmail.setHostName(BuilderConfig.getInstance().getEmailServer()); localHtmlEmail.addTo("tech@flagleader.com", "VRS"); localHtmlEmail.setAuthentication(BuilderConfig.getInstance().getEmailUser(), BuilderConfig.getInstance().getEmailPasswd()); localHtmlEmail.setFrom(this.f.getText(), this.f.getText()); localHtmlEmail.setSubject(this.c.getText() + "request rule builder license."); localHtmlEmail.setCharset("UTF-8"); StringBuffer localStringBuffer = new StringBuffer(); localStringBuffer.append("user:" + this.d.getText()).append(FileUtil.newline); localStringBuffer.append("mobile:" + this.e.getText()).append(FileUtil.newline); localStringBuffer.append("company:" + this.c.getText()).append(FileUtil.newline); localStringBuffer.append("checkCode:" + this.b).append(FileUtil.newline); localStringBuffer.append(this.a.getText()); localHtmlEmail.setHtmlMsg(localStringBuffer.toString()); localHtmlEmail.setMsg(localStringBuffer.toString()); localHtmlEmail.send(); super.okPressed(); } catch (Exception localException) { MessageDialog.openError(null, "", localException.getMessage()); } }
From source file:be.thomasmore.controller.EmailController.java
public String sendEmail() throws EmailException { Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext() .getRequestParameterMap();//from w ww . j a v a 2 s . c o m String id = params.get("studentId"); int studentId = Integer.parseInt(id); Student student = service.getStudent(studentId); HtmlEmail email = new HtmlEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator("pointernulltest@gmail.com", "r0449914")); email.setSSLOnConnect(true); email.addTo(student.getEmail(), student.getNaam() + " " + student.getVoornaam()); email.setFrom("me@apache.org", "Thomas More Geel"); email.setSubject("Rapport"); StringBuffer msg = new StringBuffer(); msg.append("<html><body>"); msg.append("<h2>Resultaten</h2>"); List<Score> scores = student.getScoreList(); msg.append("<p>Beste " + student.getVoornaam() + " " + student.getNaam() + " hieronder vind je je punten voor afgelopen semester."); for (Score score : scores) { msg.append("<p>"); msg.append(score.getTestId().getVakId().getNaam() + " " + score.getTestId().getBeschrijving() + " : " + score.getScore()); msg.append("</p>"); msg.append("</body></html>"); } email.setHtmlMsg(msg.toString()); email.send(); return null; }
From source file:com.smi.travel.util.Mail.java
public String sendmailwithAttchfile(String sendTo, String subject, String content, String attachfile, String sendCc) throws EmailException { String result = ""; boolean send = false; EmailAttachment attachment = new EmailAttachment(); HtmlEmail email = new HtmlEmail(); try {//w w w . ja v a 2 s . co m if ((attachfile != null) && (!attachfile.equalsIgnoreCase(""))) { //attachment.setPath("C:\\Users\\Surachai\\Documents\\NetBeansProjects\\SMITravel\\test.txt"); attachment.setPath(attachfile); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("file attachment"); attachment.setName("text.txt"); email.attach(attachment); } send = true; } catch (EmailException ex) { System.out.println("Email Exception"); ex.printStackTrace(); result = "fail"; } if (send) { System.out.println(mail.getUsername() + mail.getPassword()); email.setHostName(mail.getHostname()); email.setSmtpPort(mail.getPort()); email.setAuthentication(mail.getUsername(), mail.getPassword()); email.setSSLOnConnect(true); email.setFrom(mail.getUsername()); email.setSubject(subject); email.setHtmlMsg(content); String[] toSplit = sendTo.split("\\,"); for (int i = 0; i < toSplit.length; i++) { System.out.println("Print toSplit" + toSplit[i]); email.addTo(toSplit[i]); } if (!sendCc.isEmpty()) { String[] ccSplit = sendCc.split("\\,"); for (int i = 0; i < ccSplit.length; i++) { System.out.println("Print ccSplit" + ccSplit[i]); email.addCc(ccSplit[i]); } } email.send(); result = "success"; } return result; }
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"); }//from ww w . j a va2 s.co m 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:Email.CommonsEmail.java
/** * funo para enviar email// w w w . java2 s.co m * * @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:com.duroty.service.Mailet.java
/** * DOCUMENT ME!/* w ww. j av a 2 s. co m*/ * * @param username DOCUMENT ME! * @param to DOCUMENT ME! */ private void sendVacationMessage(String username, String to) { SessionFactory hfactory = null; Session hsession = null; javax.mail.Session msession = null; try { hfactory = (SessionFactory) ctx.lookup(hibernateSessionFactory); hsession = hfactory.openSession(); msession = (javax.mail.Session) ctx.lookup(smtpSessionFactory); Users user = getUser(hsession, username); Criteria crit = hsession.createCriteria(Identity.class); crit.add(Restrictions.eq("users", getUser(hsession, username))); crit.add(Restrictions.eq("ideActive", new Boolean(true))); crit.add(Restrictions.eq("ideDefault", new Boolean(true))); Identity identity = (Identity) crit.uniqueResult(); if (identity != null) { InternetAddress _from = new InternetAddress(identity.getIdeEmail(), identity.getIdeName()); InternetAddress _to = InternetAddress.parse(to)[0]; if (_from.getAddress().equals(_to.getAddress())) { return; } HtmlEmail email = new HtmlEmail(); email.setMailSession(msession); email.setFrom(_from.getAddress(), _from.getPersonal()); email.addTo(_to.getAddress(), _to.getPersonal()); Iterator it = user.getMailPreferenceses().iterator(); MailPreferences mailPreferences = (MailPreferences) it.next(); email.setSubject(mailPreferences.getMaprVacationSubject()); email.setHtmlMsg("<p>" + mailPreferences.getMaprVacationBody() + "</p><p>" + mailPreferences.getMaprSignature() + "</p>"); email.setCharset(Charset.defaultCharset().displayName()); email.send(); } } catch (Exception e) { } finally { } }
From source file:com.ipc.service.SignUpService.java
public String sendpwmail(int uid, String key, String email) throws IOException, EmailException { System.out.println("Email : " + email); HtmlEmail sendemail = new HtmlEmail(); sendemail.setCharset("euc-kr"); sendemail.setHostName("smtp.worksmobile.com"); sendemail.addTo(email);//w ww . j a va 2 s .co m sendemail.setFrom("jinuk@ideaconcert.com", ""); sendemail.setSubject("? ."); sendemail.setAuthentication("jinuk@ideaconcert.com", "tpxmapsb1"); sendemail.setSmtpPort(465); sendemail.setSSL(true); //? sendemail.setTLS(true); sendemail.setDebug(true); String htmlmsg = "<html><div style='width:1000px; float:left; border-bottom:2px solid #45d4fe; padding-bottom:5px;box-sizing:border-box;'></div><div style='width:1000px;float:left; box-sizing:border-box; padding:15px;'><h2>? .</h2><div style='width:100%; float:left; box-sizing:border-box; border:5px solid #f9f9f9; text-align:center; padding:40px 0 40px 0;'><span> ? <br> .<br>" + key + "</span></html>"; System.out.println(htmlmsg); sendemail.setHtmlMsg(htmlmsg); try { sendemail.send(); } catch (Exception e) { System.out.println("NOTOK"); return "NOTOK"; } return "OK"; }
From source file:br.ufg.reqweb.components.MailBean.java
public void sendMailToDiscente(final Requerimento requerimento) { Thread sender = new Thread() { @Override//from w w w.j a v a2 s .c o m public void run() { try { Configuration templateConf = new Configuration(); templateConf.setObjectWrapper(new DefaultObjectWrapper()); templateConf.setDefaultEncoding("UTF-8"); templateConf.setDirectoryForTemplateLoading(new File(context.getRealPath("/reports/mail"))); Map objectRoot = new HashMap(); objectRoot.put("TITULO", LocaleBean.getDefaultMessageBundle().getString("appTitle")); objectRoot.put("DISCENTE", LocaleBean.getDefaultMessageBundle().getString("discente")); objectRoot.put("REQUERIMENTO", LocaleBean.getDefaultMessageBundle().getString("requerimento")); objectRoot.put("STATUS", LocaleBean.getDefaultMessageBundle().getString("status")); objectRoot.put("ATENDENTE", LocaleBean.getDefaultMessageBundle().getString("atendente")); objectRoot.put("OBSERVACAO", LocaleBean.getDefaultMessageBundle().getString("observacao")); objectRoot.put("matricula", requerimento.getDiscente().getMatricula()); objectRoot.put("discente", requerimento.getDiscente().getNome()); objectRoot.put("tipoRequerimento", LocaleBean.getDefaultMessageBundle() .getString(requerimento.getTipoRequerimento().getTipo())); objectRoot.put("status", LocaleBean.getDefaultMessageBundle().getString(requerimento.getStatus().getStatus())); objectRoot.put("atendente", requerimento.getAtendimento().getAtendente().getNome()); objectRoot.put("observacao", requerimento.getAtendimento().getObservacao()); URL logo = new File(context.getRealPath("/resources/img/logo-mono-mini.png")).toURI().toURL(); Template template = templateConf.getTemplate("notificacao_discente.ftl"); Writer writer = new StringWriter(); HtmlEmail email = new HtmlEmail(); String logoId = email.embed(logo, "logo"); objectRoot.put("logo", logoId); template.process(objectRoot, writer); email.setHostName(configDao.getValue("mail.mailHost")); email.setSmtpPort(Integer.parseInt(configDao.getValue("mail.smtpPort"))); String mailSender = configDao.getValue("mail.mailSender"); String user = configDao.getValue("mail.mailUser"); String password = configDao.getValue("mail.mailPassword"); boolean useSSL = Boolean.parseBoolean(configDao.getValue("mail.useSSL")); email.setAuthenticator(new DefaultAuthenticator(user, password)); email.setSSLOnConnect(useSSL); email.setFrom(mailSender); email.addTo(requerimento.getDiscente().getEmail()); email.setSubject(LocaleBean.getDefaultMessageBundle().getString("subjectMail")); email.setHtmlMsg(writer.toString()); String alternativeMessage = String.format("%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s", LocaleBean.getDefaultMessageBundle().getString("messageMail"), objectRoot.get("REQUERIMENTO"), objectRoot.get("tipoRequerimento"), objectRoot.get("STATUS"), objectRoot.get("status"), objectRoot.get("ATENDENTE"), objectRoot.get("atendente"), objectRoot.get("OBSERVACAO"), objectRoot.get("observacao")); email.setTextMsg(alternativeMessage); email.send(); System.out.println(String.format("message to discente:<%s: %s>", requerimento.getDiscente().getNome(), requerimento.getDiscente().getEmail())); } catch (EmailException | IOException | TemplateException e) { System.out.println("erro ao enviar email"); System.out.println(e); } } }; sender.start(); }