List of usage examples for org.apache.commons.mail HtmlEmail setAuthenticator
public void setAuthenticator(final Authenticator newAuthenticator)
Authenticator
to be used when authentication is requested from the mail server. From source file:org.gravidence.gravifon.email.ApacheCommonsEmailSender.java
@Override public boolean send(String toAddress, String toName, String subject, String htmlMessage, String textMessage) { HtmlEmail email = new HtmlEmail(); email.setHostName(host);//w w w.j a va 2 s . com email.setSslSmtpPort(port); email.setAuthenticator(new DefaultAuthenticator(username, password)); email.setSSLOnConnect(true); try { if (StringUtils.isBlank(toName)) { email.addTo(toAddress); } else { email.addTo(toAddress, toName); } email.setFrom(fromAddress, fromName); email.setSubject(subject); if (htmlMessage != null) { email.setHtmlMsg(htmlMessage); } if (textMessage != null) { email.setTextMsg(textMessage); } email.send(); } catch (EmailException ex) { // TODO think about throwing GravifonException LOGGER.warn(String.format("Failed to send an email to %s", toAddress), ex); return false; } return true; }
From source file:org.jevis.jealarm.AlarmHandler.java
/** * Send the Alarm mail//from ww w .j av a2 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(); } }
From source file:org.jkandasa.email.blaster.EmailUtils.java
public static HtmlEmail initializeEmail(AppProperties appProperties) throws EmailException { HtmlEmail email = new HtmlEmail(); email.setHostName(appProperties.getSmtpHost()); email.setSmtpPort(Integer.valueOf(appProperties.getSmtpPort())); if (appProperties.getUsername() != null && appProperties.getUsername().length() > 0) { email.setAuthenticator( new DefaultAuthenticator(appProperties.getUsername(), appProperties.getPassword())); }//from w ww .j av a 2s . c o m email.setSSLOnConnect(appProperties.isEnableSSL()); email.setFrom(appProperties.getFromAddress()); return email; }
From source file:org.ng200.openolympus.services.EmailService.java
@PreAuthorize(SecurityExpressionConstants.IS_ADMIN) public void sendEmail(String emailAddress, String subject, String view, String alternativeText, Map<String, Object> variables) throws MessagingException, EmailException { final Context ctx = new Context(); ctx.setVariables(variables);/*from ww w . java 2s . c o m*/ final HtmlEmail email = new HtmlEmail(); email.setHostName(this.emailHost); email.setSmtpPort(this.emailHostPort); email.setAuthenticator(new DefaultAuthenticator(this.emailLogin, this.emailPassword)); email.setSSL(true); email.setFrom(this.emailLogin); email.setSubject(subject); final String htmlContent = this.templateEngine.process(view, ctx); email.setHtmlMsg(htmlContent); email.setTextMsg(alternativeText); email.addTo(emailAddress); email.send(); }
From source file:util.Log.java
public static void relatarExceptionEmail(String className, String exception, String logPath) { /*//from w ww .j av a2 s .c o 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(); } }