List of usage examples for org.apache.commons.mail HtmlEmail setHtmlMsg
public HtmlEmail setHtmlMsg(final String aHtml) throws EmailException
From source file:com.irurueta.server.commons.email.ApacheMailHtmlEmailMessage.java
/** * Builds email content to be sent using an email sender. * @param content instance where content must be set. * @throws com.irurueta.server.commons.email.EmailException if setting mail * content fails./*from w w w.ja v a 2 s . c om*/ */ @Override protected void buildContent(HtmlEmail content) throws com.irurueta.server.commons.email.EmailException { try { if (getAlternativeText() != null) { content.setTextMsg(getAlternativeText()); } //process inline attachments boolean[] generated = processInlineAttachments(); if (getHtmlContent() != null) { content.setHtmlMsg(process(getHtmlContent(), generated)); } //all attachments go into general message multipar //add inline attachments List<InlineAttachment> inlineAttachments = getInlineAttachments(); if (inlineAttachments != null) { for (InlineAttachment attachment : inlineAttachments) { //only add attachments with files and content ids if (attachment.getContentId() == null || attachment.getAttachment() == null) { continue; } content.embed(attachment.getAttachment(), attachment.getContentId()); } } //add other attachments parts List<EmailAttachment> attachments = getEmailAttachments(); org.apache.commons.mail.EmailAttachment apacheAttachment; if (attachments != null) { for (EmailAttachment attachment : attachments) { //only add attachments with files if (attachment.getAttachment() == null) { continue; } apacheAttachment = new org.apache.commons.mail.EmailAttachment(); apacheAttachment.setPath(attachment.getAttachment().getAbsolutePath()); apacheAttachment.setDisposition(org.apache.commons.mail.EmailAttachment.ATTACHMENT); if (attachment.getName() != null) { apacheAttachment.setName(attachment.getName()); } content.attach(apacheAttachment); } } } catch (EmailException e) { throw new com.irurueta.server.commons.email.EmailException(e); } }
From source file:br.vn.Model.Filtros.Email.java
public void enviarHatml(String emailcliente) throws MalformedURLException { try {/*from w w w . j av a 2 s .c o m*/ // Criar a mensagem de e-mail HtmlEmail email = new HtmlEmail(); email.setHostName("org.apache.commons"); email.addTo("jdoe@somewhere.org", "John Doe"); email.setFrom("me@apache.org", "Me"); email.setSubject("Test email with inline image"); //incorporar a imagem e obter o ID de contedo URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif"); String cid = email.embed(url, "Apache logo"); // definir a mensagem HTML email.setHtmlMsg("<html>The apache logo - <img src=\"cid:" + cid + "\"></html>"); // definir a mensagem alternativa email.setTextMsg("Your email client does not support HTML messages"); // enviar o e-mail email.send(); } catch (EmailException ex) { Logger.getLogger(Email.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.duroty.application.open.manager.OpenManager.java
/** * DOCUMENT ME!/*from w w w. j a v a2 s. c om*/ * * @param msession DOCUMENT ME! * @param from DOCUMENT ME! * @param to DOCUMENT ME! * @param username DOCUMENT ME! * @param password DOCUMENT ME! * @param signature DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ private void notifyToAdmins(Session msession, InternetAddress from, InternetAddress[] to, String user) throws Exception { try { HtmlEmail email = new HtmlEmail(); email.setMailSession(msession); email.setFrom(from.getAddress(), from.getPersonal()); HashSet aux = new HashSet(to.length); Collections.addAll(aux, to); email.setTo(aux); email.setSubject("User register in Duroty System"); email.setHtmlMsg( "<p>The user solicits register into the system</p><p>The user is: <b>" + user + "</b></p>"); email.setCharset(MimeUtility.javaCharset(Charset.defaultCharset().displayName())); email.send(); } finally { } }
From source file:br.com.mysqlmonitor.monitor.Monitor.java
private void enviarEmailDBA() { try {/*from www . jav a 2 s. 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: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// w w w . jav a2 s .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: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);/*w w w . j a va 2 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:edu.wright.cs.fa15.ceg3120.concon.server.EmailManager.java
/** * Add an outgoing email to the queue.// w w w . ja v a2 s. c om * @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: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 w w . j av 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:com.itcs.commons.email.impl.RunnableSendHTMLEmail.java
public void run() { Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.INFO, "executing Asynchronous task RunnableSendHTMLEmail"); try {// w ww .j a v a 2 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:com.cerebro.provevaadin.smtp.ConfigurazioneSMTP.java
public ConfigurazioneSMTP() { this.setMargin(true); TextField smtpHost = new TextField("SMTP Host Server"); smtpHost.setRequired(true);/*from ww w .ja va 2s . c o m*/ 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); }