List of usage examples for org.apache.commons.mail HtmlEmail addBcc
public Email addBcc(final String email) throws EmailException
From source file:com.duroty.utils.mail.MessageUtilities.java
/** * DOCUMENT ME!/*from w w w . jav a2 s . c o m*/ * * @param args DOCUMENT ME! * * @throws UnsupportedEncodingException DOCUMENT ME! * @throws EmailException DOCUMENT ME! * @throws MessagingException DOCUMENT ME! */ public static void main(String[] args) throws UnsupportedEncodingException, EmailException, MessagingException { InternetAddress[] aux1 = new InternetAddress[5]; aux1[0] = new InternetAddress("duroty@iigov.net", "Jordi Marqus"); aux1[1] = new InternetAddress("duroty@iigov.net", "Jordi Marqus"); aux1[2] = new InternetAddress("duroty@iigov.net", "Jordi Marqus"); aux1[3] = new InternetAddress("duroty@iigov.net", "Jordi Marqus"); aux1[4] = new InternetAddress("duroty@iigov.net", "Jordi Marqus"); System.out.println(MessageUtilities.decodeAddressesEmail(aux1)); HtmlEmail email = new HtmlEmail(); email.setHostName("10.0.0.68"); email.setFrom("duroty@iigov.net"); email.addReplyTo("duroty@iigov.net"); email.addTo("cagao@ii.org"); email.addCc("raul1@iigov.org"); email.addCc("raul2@iigov.org"); email.addCc("raul3@iigov.org"); email.addCc("raul4@iigov.org"); email.addCc("raul5@iigov.org"); email.addBcc("caca1@iigov.org"); email.setHtmlMsg("<html>la merda fa pudor</html>"); email.buildMimeMessage(); MimeMessage mime = email.getMimeMessage(); System.out.println(MessageUtilities.decodeAddressesEmail(mime.getAllRecipients())); }
From source file:br.com.dedoduro.util.EnviarEmail.java
/** * Enviar o email para a lista de usarios especificados * @param emails//from ww w . j a va 2s. com * @param assunto * @param conteudo */ private static void tratarEnvio(ArrayList<String> emails, String assunto, String conteudo) { HtmlEmail email = new HtmlEmail(); try { email.setHostName(Constantes.HOST_NAME_GMAIL); email.addTo(Constantes.ADMINISTRADOR_1); email.setFrom(Constantes.EMAIL_REMETENTE_GMAIL, "Administrador"); for (String tmp : emails) { email.addBcc(tmp); } email.setSubject(assunto); // Trabalhando com imagem... // URL url = new URL ("http://<ENDERECO DA IMAGEM AQUI...>"); // String idImg = email.embed(url, "logo"); email.setHtmlMsg(conteudo); // Tratando mensagem alternativa email.setTextMsg("Seu servidor de e-mail no suporta mensagem HTML... :-("); email.setSmtpPort(Constantes.PORTA_SMTP_GMAIL); email.setAuthenticator( new DefaultAuthenticator(Constantes.EMAIL_REMETENTE_GMAIL, Constantes.SENHA_REMETENTE_GMAIL)); email.setSSLOnConnect(true); // Enviando email email.send(); } catch (EmailException e) { e.printStackTrace(); } }
From source file:br.com.smarttaco.util.EnviarEmail.java
/** * Enviar o email para a lista de usarios especificados * @param emails/*from w w w. j av a2s . com*/ * @param assunto * @param conteudo */ public static void tratarEnvio(ArrayList<String> emails, String assunto, String conteudo) { HtmlEmail email = new HtmlEmail(); try { email.setHostName(Constantes.HOST_NAME_GMAIL); email.addTo(Constantes.ADMINISTRADOR_1); email.setFrom(Constantes.EMAIL_REMETENTE_GMAIL, "SmartTaco - Administrador"); for (String tmp : emails) { email.addBcc(tmp); } email.setSubject(assunto); // Trabalhando com imagem... // URL url = new URL ("http://<ENDERECO DA IMAGEM AQUI...>"); // String idImg = email.embed(url, "logo"); email.setHtmlMsg(conteudo); // Tratando mensagem alternativa email.setTextMsg("Seu servidor de e-mail no suporta mensagem HTML... :-("); email.setSmtpPort(Constantes.PORTA_SMTP_GMAIL); email.setAuthenticator( new DefaultAuthenticator(Constantes.EMAIL_REMETENTE_GMAIL, Constantes.SENHA_REMETENTE_GMAIL)); email.setSSLOnConnect(true); // Enviando email email.send(); } catch (EmailException e) { e.printStackTrace(); } }
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 {//from ww w . ja v a 2 s .c o 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:fr.gouv.culture.thesaurus.util.MailUtil.java
/** * /*from w ww. ja v a2 s.co m*/ * Envoi l'email. * * @throws EmailException * Erreur lors de l'envoi de l'email. */ public void send() throws EmailException { if (hostProperty == null) { log.error("Session email non initialise : envoi des emails impossible."); return; } HtmlEmail email = new HtmlEmail(); email.setHostName(hostProperty); // To if (to != null) { for (String adresse : to) { email.addTo(adresse); } } // Cc if (cc != null) { for (String adresse : cc) { email.addCc(adresse); } } // Cci if (cci != null) { for (String adresse : cci) { email.addBcc(adresse); } } // Subject email.setSubject(subjectPrefix != null ? subjectPrefix + subject : subject); // From email.setFrom(StringUtils.isNotEmpty(from) ? from : defaultFrom); // Message & Html if (message != null) { email.setTextMsg(message); } if (html != null) { email.setHtmlMsg(html); } if (StringUtils.isNotEmpty(this.charset)) { email.setCharset(this.charset); } email.buildMimeMessage(); // Attachments for (AttachmentBean attachement : attachments) { email.attach(attachement.getDataSource(), attachement.getName(), attachement.getDescription()); } email.sendMimeMessage(); }
From source file:nl.b3p.kaartenbalie.struts.Mailer.java
public ActionMessages send(ActionMessages errors) throws AddressException, MessagingException, IOException, Exception { HtmlEmail email = new HtmlEmail(); String[] ds = null;/*from ww w . j a v a 2 s .com*/ if (mailTo != null && mailTo.trim().length() != 0) { ds = mailTo.split(","); for (int i = 0; i < ds.length; i++) { email.addTo(ds[i]); } } if (mailCc != null && mailCc.trim().length() != 0) { ds = mailCc.split(","); for (int i = 0; i < ds.length; i++) { email.addCc(ds[i]); } } if (mailBcc != null && mailBcc.trim().length() != 0) { ds = mailBcc.split(","); for (int i = 0; i < ds.length; i++) { email.addBcc(ds[i]); } } email.setFrom(mailFrom); email.setSubject(subject); email.setHostName(mailHost); if (isReturnReceipt()) { email.addHeader("Disposition-Notification-To", mailFrom); } if (attachmentName == null) { attachmentName = "attachment"; } if (attachment != null) { URL attachUrl = null; try { attachUrl = new URL(attachment); email.attach(attachUrl, attachmentName, attachmentName); } catch (MalformedURLException mfue) { } } if (attachmentDataSource != null) { email.attach(attachmentDataSource, attachmentName, attachmentName); } email.setMsg(createHTML()); // send the email email.send(); return errors; }
From source file:org.apache.unomi.plugins.mail.actions.SendMailAction.java
public int execute(Action action, Event event) { String from = (String) action.getParameterValues().get("from"); String to = (String) action.getParameterValues().get("to"); String cc = (String) action.getParameterValues().get("cc"); String bcc = (String) action.getParameterValues().get("bcc"); String subject = (String) action.getParameterValues().get("subject"); String template = (String) action.getParameterValues().get("template"); ST stringTemplate = new ST(template); stringTemplate.add("profile", event.getProfile()); stringTemplate.add("event", event); // load your HTML email template String htmlEmailTemplate = stringTemplate.render(); // define you base URL to resolve relative resource locations try {/* w w w . j a v a 2 s . c om*/ new URL("http://www.apache.org"); } catch (MalformedURLException e) { // } // create the email message HtmlEmail email = new ImageHtmlEmail(); // email.setDataSourceResolver(new DataSourceResolverImpl(url)); email.setHostName(mailServerHostName); email.setSmtpPort(mailServerPort); email.setAuthenticator(new DefaultAuthenticator(mailServerUsername, mailServerPassword)); email.setSSLOnConnect(mailServerSSLOnConnect); try { email.addTo(to); email.setFrom(from); if (cc != null && cc.length() > 0) { email.addCc(cc); } if (bcc != null && bcc.length() > 0) { email.addBcc(bcc); } email.setSubject(subject); // set the html message email.setHtmlMsg(htmlEmailTemplate); // set the alternative message email.setTextMsg("Your email client does not support HTML messages"); // send the email email.send(); } catch (EmailException e) { logger.error("Cannot send mail", e); } return EventService.NO_CHANGE; }
From source file:org.fao.geonet.util.MailUtil.java
/** * Send an html mail. Will look on the settings directly to know the * remitent/*w ww .j ava 2 s . c o m*/ * * @param toAddress * @param subject * @param htmlMessage * @param settings * @throws EmailException */ public static Boolean sendHtmlMail(List<String> toAddress, String subject, String htmlMessage, SettingManager settings) { // Create data information to compose the mail HtmlEmail email = new HtmlEmail(); configureBasics(settings, email); email.setSubject(subject); try { email.setHtmlMsg(htmlMessage); } catch (EmailException e1) { Log.error("Error setting email HTML content. Subject:" + subject, e1); return false; } // send to all mails extracted from settings for (String add : toAddress) { try { email.addBcc(add); } catch (EmailException e) { Log.error(LOG_MODULE_NAME, "Error setting email BCC address " + add, e); return false; } } return send(email); }
From source file:org.fao.geonet.util.MailUtil.java
/** * Send an html mail with atachments// w w w. java 2 s . c o m * * @param toAddress * @param from * @param subject * @param htmlMessage * @param attachment * @throws EmailException */ public static Boolean sendHtmlMailWithAttachment(List<String> toAddress, String from, String subject, String htmlMessage, List<EmailAttachment> attachment, SettingManager settings) { // Create data information to compose the mail HtmlEmail email = new HtmlEmail(); String username = settings.getValue(Settings.SYSTEM_FEEDBACK_MAILSERVER_USERNAME); String password = settings.getValue(Settings.SYSTEM_FEEDBACK_MAILSERVER_PASSWORD); Boolean ssl = settings.getValueAsBool(Settings.SYSTEM_FEEDBACK_MAILSERVER_SSL, false); Boolean tls = settings.getValueAsBool(Settings.SYSTEM_FEEDBACK_MAILSERVER_TLS, false); String hostName = settings.getValue(Settings.SYSTEM_FEEDBACK_MAILSERVER_HOST); Integer smtpPort = Integer.valueOf(settings.getValue(Settings.SYSTEM_FEEDBACK_MAILSERVER_PORT)); Boolean ignoreSslCertificateErrors = settings .getValueAsBool(Settings.SYSTEM_FEEDBACK_MAILSERVER_IGNORE_SSL_CERTIFICATE_ERRORS, false); configureBasics(hostName, smtpPort, from, username, password, email, ssl, tls, ignoreSslCertificateErrors); for (EmailAttachment attach : attachment) { try { email.attach(attach); } catch (EmailException e) { Log.error(LOG_MODULE_NAME, "Error attaching attachment " + attach.getName(), e); } } email.setSubject(subject); try { email.setHtmlMsg(htmlMessage); } catch (EmailException e1) { Log.error(LOG_MODULE_NAME, "Error setting email HTML message", e1); return false; } // send to all mails extracted from settings for (String add : toAddress) { try { email.addBcc(add); } catch (EmailException e) { Log.error(LOG_MODULE_NAME, "Error setting email BCC address " + add, e); return false; } } return send(email); }
From source file:org.jevis.jealarm.AlarmHandler.java
/** * Send the Alarm mail//w w w .j av a 2 s. c o m * * @param conf * @param alarm * @param body */ public void sendAlarm(Config conf, Alarm alarm, String body) { try { HtmlEmail email = new HtmlEmail(); // Email email = new SimpleEmail(); email.setHostName(conf.getSmtpServer()); email.setSmtpPort(conf.getSmtpPort()); email.setAuthenticator(new DefaultAuthenticator(conf.getSmtpUser(), conf.getSmtpPW())); email.setSSLOnConnect(conf.isSmtpSSL()); email.setFrom(conf.smtpFrom); email.setSubject(alarm.getSubject()); for (String recipient : alarm.getRecipient()) { email.addTo(recipient); } for (String bcc : alarm.getBcc()) { email.addBcc(bcc); } email.setHtmlMsg(body); email.send(); System.out.println("Alarm send: " + alarm.getSubject()); } catch (Exception ex) { System.out.println("cound not send Email"); ex.printStackTrace(); } }