List of usage examples for org.apache.commons.mail HtmlEmail buildMimeMessage
@Override public void buildMimeMessage() throws EmailException
From source file:com.duroty.utils.mail.MessageUtilities.java
/** * DOCUMENT ME!//from w ww .j a v a 2s.co 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:io.marto.aem.utils.email.FreemarkerTemplatedMailerTest.java
private String getEmail(HtmlEmail htmlMail) throws EmailException, IOException, MessagingException, UnsupportedEncodingException { htmlMail.setHostName("localhost"); htmlMail.buildMimeMessage(); ByteArrayOutputStream out = new ByteArrayOutputStream(); htmlMail.getMimeMessage().writeTo(out); return out.toString("UTF-8"); }
From source file:fr.gouv.culture.thesaurus.util.MailUtil.java
/** * //from w ww. ja va 2 s. c o 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:com.duroty.application.chat.manager.ChatManager.java
/** * DOCUMENT ME!// w w w. j a v a 2 s .c o m * * @param hsession DOCUMENT ME! * @param userSender DOCUMENT ME! * @param userRecipient DOCUMENT ME! */ private void sendMail(Session hsession, javax.mail.Session msession, Users userSender, Users userRecipient, String message) { try { String sender = userSender.getUseUsername(); String recipient = userRecipient.getUseUsername(); Identity identitySender = getIdentity(hsession, userSender); Identity identityRecipient = getIdentity(hsession, userRecipient); HtmlEmail email = new HtmlEmail(); InternetAddress _from = new InternetAddress(identitySender.getIdeEmail(), identitySender.getIdeName()); InternetAddress _replyTo = new InternetAddress(identitySender.getIdeReplyTo(), identitySender.getIdeName()); InternetAddress[] _to = MessageUtilities.encodeAddresses(identityRecipient.getIdeEmail(), null); if (_from != null) { email.setFrom(_from.getAddress(), _from.getPersonal()); } if (_replyTo != null) { email.addReplyTo(_replyTo.getAddress(), _replyTo.getPersonal()); } if ((_to != null) && (_to.length > 0)) { HashSet aux = new HashSet(_to.length); Collections.addAll(aux, _from); Collections.addAll(aux, _to); email.setTo(aux); } email.setCharset(charset); email.setSubject("Chat " + sender + " >> " + recipient); email.setHtmlMsg(message); calendar.setTime(new Date()); String minute = "30"; if (calendar.get(Calendar.MINUTE) >= 30) { minute = "60"; } String value = String.valueOf(calendar.get(Calendar.YEAR)) + String.valueOf(calendar.get(Calendar.MONTH)) + String.valueOf(calendar.get(Calendar.DATE)) + String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)) + minute + String.valueOf(userSender.getUseIdint() + userRecipient.getUseIdint()); String reference = "<" + value + ".JavaMail.duroty@duroty" + ">"; email.addHeader(RFC2822Headers.IN_REPLY_TO, reference); email.addHeader(RFC2822Headers.REFERENCES, reference); email.addHeader("X-DBox", "CHAT"); Date now = new Date(); email.setSentDate(now); email.setMailSession(msession); email.buildMimeMessage(); MimeMessage mime = email.getMimeMessage(); int size = MessageUtilities.getMessageSize(mime); if (controlQuota(hsession, userSender, size)) { //messageable.saveSentMessage(null, mime, userSender); Thread thread = new Thread(new SendMessageThread(email)); thread.start(); } } catch (UnsupportedEncodingException e) { } catch (MessagingException e) { } catch (EmailException e) { } catch (Exception e) { } }
From source file:com.moss.error_reporting.server.Notifier.java
public void sendEmailNotification(ReportId id, ErrorReport report) { try {//w w w . j a v a 2 s.co m HtmlEmail email = new HtmlEmail(); prepEmail(email, id); StringBuffer body = new StringBuffer(); body.append("<html><body>"); List<ErrorReportChunk> chunks = report.getReportChunks(); for (int x = 0; x < chunks.size(); x++) { ErrorReportChunk chunk = chunks.get(x); body.append("<div style=\"padding:5px;text-align:center;border:1px solid black;\">"); body.append("<span style=\"font-weight:bold;\">" + chunk.getName() + "</span>"); body.append("<span style=\"font-style:italic;\">[" + chunk.getMimeType() + "</span>]"); body.append("</div>"); String mimeType = chunk.getMimeType(); if (mimeType != null && mimeType.equals("text/plain")) { body.append( "<div style=\"border:1px solid black;border-top:0px;padding:5px;background:#dddddd;\"><pre>"); boolean needsTruncation = chunk.getData().length > MAX_MESSAGE_LENGTH; int length = needsTruncation ? MAX_MESSAGE_LENGTH : chunk.getData().length; body.append(new String(chunk.getData(), 0, length)); if (needsTruncation) { body.append("\n"); body.append((chunk.getData().length - MAX_MESSAGE_LENGTH) + " more bytes"); } body.append("</pre></div>"); } else if (mimeType != null && mimeType.equals("application/zip")) { body.append( "<div style=\"border:1px solid black;border-top:0px;padding:5px;background:#dddddd;\"><pre>"); ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(chunk.getData())); try { new ZipToTextTool().run(in, body); } catch (IOException e) { e.printStackTrace(); body.append("Error Reading Zip:" + e.getMessage()); } body.append("</pre></div>"); } if (x != chunks.size() - 1 && chunks.size() > 1) body.append("<br/><br/>"); } body.append("</body></html>"); // email.setHtmlMsg("<html><body>Hello World</body></html>"); email.setHtmlMsg(body.toString()); // email.setTextMsg("HTML EMAIL"); email.buildMimeMessage(); email.sendMimeMessage(); } catch (EmailException e) { e.printStackTrace(); } }