List of usage examples for org.apache.commons.mail HtmlEmail send
public String send() throws EmailException
From source file:org.xmatthew.spy2servers.component.util.EMailUtils.java
/** * <p>/*from ww w. jav a 2 s. c o m*/ * send html body mail * </p> * * @param mailBody * @throws EmailException email about exception */ public static void sendHtmlEmail(MailBody mailBody) throws EmailException { HtmlEmail email = new HtmlEmail(); email.setHostName(mailBody.getLoginServer()); email.setAuthentication(mailBody.getLoginName(), mailBody.getLoginPassword()); //receivers Map<String, String> receivers = mailBody.getReceivers(); parseReceivers(email, receivers); //cc receivers receivers = mailBody.getCcReceivers(); parseCCRecievers(email, receivers); //attatchments Map<String, EmailAttachment> attatchments = mailBody.getAttachments(); parseAttatchments(email, attatchments); String aHtml = mailBody.getAHtml(); if (StringUtils.isNotBlank(aHtml)) { email.setHtmlMsg(aHtml); } email.setFrom(mailBody.getSender(), mailBody.getSender_nick()); email.setSubject(mailBody.getSubject()); email.setMsg(mailBody.getBody()); email.send(); }
From source file:org.yestech.notify.deliver.HtmlEmailDelivery.java
protected void sendMessage(INotification notification, IRecipient recipient) throws EmailException { // Create the email message HtmlEmail email = new HtmlEmail(); enableAuthenticator(email);//from w ww . j a v a 2 s .c om email.setHostName(getEmailHost()); ISender sender = notification.getSender(); email.setFrom(sender.getEmailAddress(), sender.getDisplayName()); if (StringUtils.isNotBlank(sender.getReplyAddress())) { email.addReplyTo(sender.getReplyAddress()); } email.setSubject(notification.getMessage().getSubject()); email.addTo(recipient.getEmailAddress(), recipient.getDisplayName()); ITemplateLanguage template = notification.getTemplate(); String appliedMessage = template.apply(notification.getMessage()); email.setHtmlMsg(appliedMessage); email.send(); }
From source file:sk.baka.webvm.analyzer.utils.NotificationDelivery.java
/** * Sends a mail with given report.//from w ww . j a v a 2s .co m * @param config the mail server configuration. * @param testing if true then a testing mail is sent * @param reports the current reports * @throws org.apache.commons.mail.EmailException if sending mail fails. */ public static void sendEmail(final Config config, final boolean testing, final List<ProblemReport> reports) throws EmailException { if (!isEmailEnabled(config)) { return; } final HtmlEmail mail = new HtmlEmail(); configure(mail, config); mail.setSubject("WebMon: Problems notification" + (testing ? " (testing mail)" : "")); mail.setMsg(ProblemReport.toString(reports, "\n")); mail.setHtmlMsg("<html><body>\n" + ProblemReport.toHtml(reports) + "\n</body></html>"); mail.send(); }
From source file:tilda.utils.MailUtil.java
/** * //from w ww. j a v a2 s . c o m * @param SmtpInfo A string such as smtp.mydomain.com:422:ssl to connect to an SMTP server * @param From the user ID used to send emails from * @param Password The password for the account we send emails from * @param To Destination email(s) * @param Cc CC email(s) * @param Bcc BCC emails(s) * @param Subject The Subject * @param Message The message (HTML allowed) * @param Urgent Whether to send the message as urgent or not. * @return */ public static boolean send(String SmtpInfo, String From, String Password, String[] To, String[] Cc, String[] Bcc, String Subject, String Message, boolean Urgent) { String LastAddress = null; try { HtmlEmail email = new HtmlEmail(); String[] parts = SmtpInfo.split(":"); email.setHostName(parts[0]); if (parts.length > 1) { if (parts.length > 2 && parts[2].equalsIgnoreCase("ssl") == true) { email.setSslSmtpPort(parts[1]); email.setSSLOnConnect(true); } else { email.setSmtpPort(Integer.parseInt(parts[1])); } } email.setAuthentication(From, Password); email.setSubject(Subject); LOG.debug("Sending an email '" + email.getSubject() + "'."); if (To != null) for (String s : To) { if (TextUtil.isNullOrEmpty(s) == true) continue; LastAddress = s; email.addTo(s); } if (Cc != null) for (String s : Cc) { if (TextUtil.isNullOrEmpty(s) == true) continue; LastAddress = s; email.addCc(s); } if (Bcc != null) for (String s : Bcc) { if (TextUtil.isNullOrEmpty(s) == true) continue; LastAddress = s; email.addBcc(s); } if (LastAddress == null) { LOG.debug("No recipient. Not sending anything."); return true; } email.setFrom(From); LastAddress = From; email.setHtmlMsg(Message); if (Urgent == true) email.addHeader("X-Priority", "1"); LastAddress = null; email.send(); return true; } catch (EmailException E) { if (LastAddress != null) LOG.debug("Email address '" + LastAddress + "' seems to be invalid."); LOG.error(E); return false; } }
From source file:util.Log.java
public static void relatarExceptionEmail(String className, String exception, String logPath) { /*/*from w ww . j a v a2 s . co m*/ * Para compreender melhor acesse esse site: * http://www.botecodigital.info/java/enviando-e-mail-em-java-com-api- * commons-email-da-apache/ */ HtmlEmail email = new HtmlEmail(); email.setSSLOnConnect(true); email.setHostName("smtp.gmail.com"); email.setSslSmtpPort("465"); email.setAuthenticator(new DefaultAuthenticator("jjsoftwares10@gmail.com", "jean1420")); try { email.setFrom("jjsoftwares10@gmail.com", "Software da clinica"); email.setSubject("Exceo ocorrida no app da clinica"); StringBuilder msg = new StringBuilder(); msg.append("<h1 style=\"text-align: center;\">Excecao Ocorrida</h1>"); msg.append("<p><strong>Na Classe: " + className + " </strong></p>"); msg.append("<p><strong>Data e Horario do ocorrido: " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:s")) + "</strong></p>"); msg.append("<h2 style=\"text-align: center;\"><strong>Excecao</strong></h2>"); msg.append("<p><span style=\"color: #ff0000;\">" + exception + "</span></p>"); msg.append("<p><strong>Segue anexo com detalhes</strong></p>"); /*Enviando o anexo com detalhes da exceo*/ File arqLog = new File(logPath); if (arqLog.exists()) { EmailAttachment anexo = new EmailAttachment(); anexo.setPath(logPath); anexo.setDisposition(EmailAttachment.ATTACHMENT); anexo.setName(arqLog.getName()); email.attach(anexo); } /*enviando*/ email.setHtmlMsg(msg.toString()); email.addTo("jeandersonfju@gmail.com"); email.addTo("jeff-assis@hotmail.com"); email.send(); } catch (EmailException e) { e.printStackTrace(); } }