List of usage examples for org.apache.commons.mail Email setAuthentication
public void setAuthentication(final String userName, final String password)
From source file:br.fgv.util.EmailSender.java
public static void enviarEmail(String body, String subject) throws EmailException { StringBuffer sb = new StringBuffer(""); sb.append(body);//from w ww . j av a 2 s . co m Email email = new SimpleEmail(); email.setHostName("smtp.gmail.com"); email.setDebug(true); email.setSSLOnConnect(true); email.addTo("wesley.seidel@gmail.com"); email.setAuthentication("wseidel.fgv", "batavinhofgv"); email.setFrom("wseidel.fgv@gmail.com"); email.setSubject(subject); email.setMsg(sb.toString()); email.send(); }
From source file:model.EmailJava.java
public static void enviarEmail(String userEmail) { try {//w ww. j a va 2s .c om Email email = new SimpleEmail(); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465); //email.setAuthenticator(new DefaultAuthenticator("username", "password")); email.setAuthentication("codbarzmgbr@gmail.com ", "streetworkout2014"); email.setSSLOnConnect(true); email.setFrom("jpmuniz88@gmail.com"); email.setSubject("CodbarZ"); email.setMsg("Junte-se ao CodbarZ. \n" + "Atleta junte-se ao nosso time, \n" + "empreendedores junte-se para nos apoiar, \n" + "Associe essa ideia, um projeto de inovado e aberto a todos que desejar evoluir com CodbarZ"); email.addTo(userEmail); email.send(); } catch (EmailException ex) { Logger.getLogger(EmailJava.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ar.com.pahema.utils.MailSender.java
public static void enviar(String destino, Paquete paquete) throws EmailException { try {/*from w ww . j a v a 2 s. c om*/ Email mail = new SimpleEmail(); //Configuracion necesaria para GMAIL mail.setHostName("mail.pahema.com.ar"); //mail.setTLS(true); mail.setSmtpPort(25); //mail.setSSL(true); //En esta seccion colocar cuenta de usuario de Gmail y contrasea mail.setAuthentication("dante@pahema.com.ar", "Fuerza2015"); //Cuenta de Email Destino // AC? IRIA LA DE ADMINISTRACION DE PAHEMA. mail.addTo("dante.gs@hotmail.com"); mail.addTo(destino); //Cuenta de Email Origen, la misma con la que nos autenticamos mail.setFrom("dante@pahema.com.ar", "Pahema - Sistema Tango"); //Titulo del Email mail.setSubject("Aviso de finalizacin de paquete de horas."); //Contenido del Email mail.setMsg("Estimado cliente,\n" + "Le informamos que su paquete de " + (int) paquete.getCantidadHoras() + " horas est por finalizar.\n" + "Le quedan por usar: " + (int) paquete.getHorasRestantes() + " horas.\n" + "Por favor comunquese con Pahema para el detalle de sus consumos: 4952 - 4789.\n" + "Muchas gracias.\n" + "Administracin."); mail.send(); } catch (EmailException e) { System.out.println(e.getMessage()); throw new RuntimeException("Ocurrio un error en el envio del mail"); } }
From source file:com.github.triceo.robozonky.notifications.email.AbstractEmailingListener.java
private static Email createNewEmail(final EmailNotificationProperties properties) throws EmailException { final Email email = new SimpleEmail(); email.setCharset(Defaults.CHARSET.displayName()); email.setHostName(properties.getSmtpHostname()); email.setSmtpPort(properties.getSmtpPort()); email.setStartTLSRequired(properties.isStartTlsRequired()); email.setSSLOnConnect(properties.isSslOnConnectRequired()); email.setAuthentication(properties.getSmtpUsername(), properties.getSmtpPassword()); email.setFrom(properties.getSender(), "RoboZonky @ " + properties.getLocalHostAddress()); email.addTo(properties.getRecipient()); return email; }
From source file:gobblin.util.EmailUtils.java
/** * A general method for sending emails.// w w w .j a va2s .c o m * * @param state a {@link State} object containing configuration properties * @param subject email subject * @param message email message * @throws EmailException if there is anything wrong sending the email */ public static void sendEmail(State state, String subject, String message) throws EmailException { Email email = new SimpleEmail(); email.setHostName(state.getProp(ConfigurationKeys.EMAIL_HOST_KEY, ConfigurationKeys.DEFAULT_EMAIL_HOST)); if (state.contains(ConfigurationKeys.EMAIL_SMTP_PORT_KEY)) { email.setSmtpPort(state.getPropAsInt(ConfigurationKeys.EMAIL_SMTP_PORT_KEY)); } email.setFrom(state.getProp(ConfigurationKeys.EMAIL_FROM_KEY)); if (state.contains(ConfigurationKeys.EMAIL_USER_KEY) && state.contains(ConfigurationKeys.EMAIL_PASSWORD_KEY)) { email.setAuthentication(state.getProp(ConfigurationKeys.EMAIL_USER_KEY), PasswordManager .getInstance(state).readPassword(state.getProp(ConfigurationKeys.EMAIL_PASSWORD_KEY))); } Iterable<String> tos = Splitter.on(',').trimResults().omitEmptyStrings() .split(state.getProp(ConfigurationKeys.EMAIL_TOS_KEY)); for (String to : tos) { email.addTo(to); } String hostName; try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException uhe) { LOGGER.error("Failed to get the host name", uhe); hostName = "unknown"; } email.setSubject(subject); String fromHostLine = String.format("This email was sent from host: %s%n%n", hostName); email.setMsg(fromHostLine + message); email.send(); }
From source file:com.clavain.alerts.Methods.java
private static void sendMail(String title, String message, String emailaddy) { try {//from w w w. ja v a 2 s.c om Email email = new SimpleEmail(); email.setHostName(p.getProperty("mailserver.host")); email.setSmtpPort(Integer.parseInt(p.getProperty("mailserver.port"))); if (p.getProperty("mailserver.useauth").equals("true")) { email.setAuthentication(p.getProperty("mailserver.user"), p.getProperty("mailserver.pass")); } if (p.getProperty("mailserver.usessl").equals("true")) { email.setSSLOnConnect(true); } else { email.setSSLOnConnect(false); } email.setFrom(p.getProperty("mailserver.from")); email.setSubject("[MuninMX] " + title); email.setMsg(message); email.addTo(emailaddy); email.send(); } catch (Exception ex) { logger.warn("Unable to send Mail: " + ex.getLocalizedMessage()); } }
From source file:com.kylinolap.common.util.MailService.java
/** * // ww w . j a v a 2s . c o m * @param receivers * @param subject * @param content * @return true or false indicating whether the email was delivered successfully * @throws IOException */ public boolean sendMail(List<String> receivers, String subject, String content) throws IOException { if (!enabled) { logger.info("Email service is disabled; this mail will not be delivered: " + subject); logger.info("To enable mail service, set 'mail.enabled=true' in kylin.properties"); return false; } Email email = new HtmlEmail(); email.setHostName(host); if (username != null && username.trim().length() > 0) { email.setAuthentication(username, password); } //email.setDebug(true); try { for (String receiver : receivers) { email.addTo(receiver); } email.setFrom(sender); email.setSubject(subject); email.setCharset("UTF-8"); ((HtmlEmail) email).setHtmlMsg(content); email.send(); email.getMailSession(); } catch (EmailException e) { logger.error(e.getLocalizedMessage(), e); return false; } return true; }
From source file:com.pax.pay.trans.receipt.paperless.AReceiptEmail.java
private int setBaseInfo(EmailInfo emailInfo, Email email) { try {/* w w w . jav a2 s .c o m*/ //email.setDebug(true); email.setHostName(emailInfo.getHostName()); email.setSmtpPort(emailInfo.getPort()); email.setAuthentication(emailInfo.getUserName(), emailInfo.getPassword()); email.setCharset("UTF-8"); email.setSSLOnConnect(emailInfo.isSsl()); if (emailInfo.isSsl()) email.setSslSmtpPort(String.valueOf(emailInfo.getSslPort())); email.setFrom(emailInfo.getFrom()); } catch (EmailException e) { e.printStackTrace(); return -1; } return 0; }
From source file:com.ning.billing.util.email.DefaultEmailSender.java
private void sendEmail(final List<String> to, final List<String> cc, final String subject, final Email email) throws EmailApiException { try {//from w ww. jav a 2 s. c o m email.setSmtpPort(config.getSmtpPort()); if (config.useSmtpAuth()) { email.setAuthentication(config.getSmtpUserName(), config.getSmtpPassword()); } email.setHostName(config.getSmtpServerName()); email.setFrom(config.getDefaultFrom()); email.setSubject(subject); if (to != null) { for (final String recipient : to) { email.addTo(recipient); } } if (cc != null) { for (final String recipient : cc) { email.addCc(recipient); } } email.setSSL(config.useSSL()); log.info("Sending email to {}, cc {}, subject {}", new Object[] { to, cc, subject }); email.send(); } catch (EmailException ee) { throw new EmailApiException(ee, ErrorCode.EMAIL_SENDING_FAILED); } }
From source file:br.com.verificanf.bo.NotaBO.java
public void buscar() { /*Inicio - Pegar Configuraes de email do arquivo*/ try {/*from w ww. j a v a2 s. co m*/ String local = new File("./email.txt").getCanonicalFile().toString(); File arq = new File(local); boolean existe = arq.exists(); if (existe) { FileReader fr = new FileReader(arq); BufferedReader br = new BufferedReader(fr); while (br.ready()) { String linha = br.readLine(); if (linha.contains("host:")) { hostEmail = linha.replace("host:", "").replace(" ", ""); } if (linha.contains("port:")) { portEmail = linha.replace("port:", "").replace(" ", ""); } if (linha.contains("user:")) { userEmail = linha.replace("user:", "").replace(" ", ""); } if (linha.contains("pass:")) { passEmail = linha.replace("pass:", "").replace(" ", ""); } if (linha.contains("from:")) { fromEmail = linha.replace("from:", "").replace(" ", ""); } if (linha.contains("to:")) { toEmail = linha.replace("to:", "").replace(" ", ""); } } } } catch (FileNotFoundException ex) { Logger.getLogger(NotaBO.class.getName()).log(Level.SEVERE, null, ex); StackTraceElement st[] = ex.getStackTrace(); String erro = ""; for (int i = 0; i < st.length; i++) { erro += st[i].toString() + "\n"; } } catch (IOException ex) { Logger.getLogger(NotaBO.class.getName()).log(Level.SEVERE, null, ex); StackTraceElement st[] = ex.getStackTrace(); String erro2 = ""; for (int i = 0; i < st.length; i++) { erro2 += st[i].toString() + "\n"; } } /*FIM - Pegar Configuraes de email do arquivo*/ NotaDAO notaDAO = new NotaDAO(); try { ultimasAtual = notaDAO.getUltimaNotaMesAtual(); ultimasAnterior = notaDAO.getUltimaNotaMesAnterior(); naoEncontradas = new ArrayList<>(); for (Nota notaAnterior : ultimasAnterior) { for (Nota notaAtual : ultimasAtual) { if (notaAnterior.getLoja() == notaAtual.getLoja()) { //System.out.println("Anterior Loja: "+notaAnterior.getLoja()+" Nota: "+notaAnterior.getNumero()); //System.out.println("Atual Loja: "+notaAtual.getLoja()+" Nota: "+notaAtual.getNumero()); Integer numero = 0; for (Integer i = notaAnterior.getNumero(); i <= notaAtual.getNumero(); i++) { numero = i; Nota notacorrente = new Nota(); notacorrente.setLoja(notaAnterior.getLoja()); notacorrente.setNumero(numero); notacorrente.setSerie(notaAnterior.getSerie()); //System.out.println("Corrente Loja: "+notacorrente.getLoja()+" Nota: "+notacorrente.getNumero()); if (!notaDAO.notaIsValida(notacorrente)) { System.out.println("Loja " + notaAnterior.getLoja() + " Numero: " + numero); naoEncontradas.add(notacorrente); msg = msg.concat(" Loja: " + notacorrente.getLoja() + " Nota: " + notacorrente.getNumero() + " Serie: " + notacorrente.getSerie() + " \n"); } } } } } if (naoEncontradas.size() > 0) { Email email = new SimpleEmail(); email.setHostName(hostEmail); email.setSmtpPort(Integer.parseInt(portEmail)); email.setAuthentication(userEmail, passEmail); email.setFrom(fromEmail); email.setSubject("Alerta Nerus!!"); email.setMsg(msg); email.addTo(toEmail); email.send(); } } catch (Exception ex) { Logger.getLogger(NotaBO.class.getName()).log(Level.SEVERE, null, ex); } }