List of usage examples for org.apache.commons.mail Email setAuthenticator
public void setAuthenticator(final Authenticator newAuthenticator)
Authenticator
to be used when authentication is requested from the mail server. From source file:org.pepstock.jem.notify.engine.EmailNotifier.java
/** * This method sends an <code>Email</code>. <br> * It sets in the parameter <code>Email</code> the properties of the * parameter <code>JemEmail</code>: From User Email Address, From User Name, * subject, text, email destination addresses. <br> * It sets in the parameter <code>Email</code> the Email Server property and * the optional <code>SMTP</code> port, the properties that indicates if it * must use <code>SSL</code> and <code>TLS</code> protocol, the useirid and * password for <code>SMTP</code> server authentication if needed, the * optional bounce address, the subject, the text, and the recipients of the * email.//from ww w . j a v a 2s .co m * * @param email the <code>JemEmail</code> with the properties of the email * to be sent. * @param sendingEmail the real <code>Email</code> that will be sent. * @see JemEmail * @see Email * @throws SendMailException if an error occurs. */ private void sendEmail(JemEmail email, Email sendingEmail) throws SendMailException { try { sendingEmail.setHostName(this.emailServer); if (this.smtpPort != NO_SMTP_PORT) { sendingEmail.setSmtpPort(this.smtpPort); } sendingEmail.setFrom(email.getFromUserEmailAddress(), email.getFromUserName()); if (email.hasSubject()) { sendingEmail.setSubject(email.getSubject()); } else { // log no subject LogAppl.getInstance().emit(NotifyMessage.JEMN014W, "Subject"); } if (email.hasText()) { sendingEmail.setMsg(email.getText()); } else { // log no text message LogAppl.getInstance().emit(NotifyMessage.JEMN014W, "Text Message"); } sendingEmail.setTo(email.getAllToEmailAddresses()); if (null != this.bounceAddress) { sendingEmail.setBounceAddress(this.bounceAddress); } sendingEmail.setSentDate(new Date()); sendingEmail.setSSL(this.isSSL); sendingEmail.setTLS(this.isTLS); if (null != this.authenticationUserId && null != this.authenticationPassword) { sendingEmail.setAuthenticator( new DefaultAuthenticator(this.authenticationUserId, this.authenticationPassword)); } sendingEmail.send(); LogAppl.getInstance().emit(NotifyMessage.JEMN015I, email); } catch (EmailException eEx) { LogAppl.getInstance().emit(NotifyMessage.JEMN016E, eEx, email); throw new SendMailException(NotifyMessage.JEMN016E.toMessage().getFormattedMessage(email), eEx); } }
From source file:org.polymap.rhei.um.email.EmailService.java
public void send(Email email) throws EmailException { String env = System.getProperty("org.polymap.rhei.um.SMTP"); if (env == null) { throw new IllegalStateException( "Environment variable missing: org.polymap.rhei.um.SMTP. Format: <host>|<login>|<passwd>|<from>"); }/* w w w. ja v a 2 s.co m*/ String[] parts = StringUtils.split(env, "|"); if (parts.length < 3 || parts.length > 4) { throw new IllegalStateException( "Environment variable wrong: org.polymap.rhei.um.SMTP. Format: <host>|<login>|<passwd>|<from> : " + env); } email.setDebug(true); email.setHostName(parts[0]); //email.setSmtpPort( 465 ); //email.setSSLOnConnect( true ); email.setAuthenticator(new DefaultAuthenticator(parts[1], parts[2])); if (email.getFromAddress() == null && parts.length == 4) { email.setFrom(parts[3]); } if (email.getSubject() == null) { throw new EmailException("Missing subject."); } email.send(); }
From source file:paquetes.AlertSchedule.java
@Schedule(hour = "8", dayOfWeek = "*", info = "Todos los dias a las 8:00 a.m.") //@Schedule(second = "*", minute = "*/10", hour = "*", persistent= true, info = "cada 10 minutos") public void performTask() throws EmailException { long timeInit = System.currentTimeMillis(); ConfiguracionMail();// ww w.j ava2s.com log.info(":. Inicio TareaProgramada cada dia"); try { timeInit = System.currentTimeMillis(); obtenerAlertas(); // Luego de obtener las alertas las recorremos para conformar cada uno de los selects de validacion alertas.stream().forEach((ale) -> { id_ale = ale.getId_ale(); llenarAlertasUsuarios(ale.getId_ale()); verificarPorTipoAlerta(ale); nom_tip_ale = ale.getNom_tip_ale(); logale.stream().forEach((lgal) -> { try { Email email = new SimpleEmail(); email.setHostName(this.hostname); email.setSmtpPort(Integer.parseInt(this.smtp_port)); email.setAuthenticator(new DefaultAuthenticator(this.user, this.pass)); // TLS agregado para server AWS Se quita comentario a setSSL. email.setStartTLSEnabled(true); email.setStartTLSRequired(true); // Comentariado para funcionar con Gmail //email.setSSLOnConnect(true); email.setFrom(this.remitente); email.setSubject(nom_tip_ale); email.setMsg(lgal.getAle_des()); alertasusuarios.stream().forEach((mailDestino) -> { try { email.addTo(mailDestino.getMailusu()); } catch (Exception e) { System.out.println("Error en la obtencion de destinatarios. " + e.getMessage()); } }); email.send(); } catch (Exception e) { System.out.println("Error en la conformacion del correo. " + e.getMessage()); } }); }); } catch (Exception e) { log.error("Error en la tarea programada"); log.info(e); } long time = System.currentTimeMillis(); time = System.currentTimeMillis() - timeInit; log.info(":. Fin tarea programada. Tiempo de proceso = " + time); }
From source file:rapternet.irc.bots.wheatley.listeners.AutodlText.java
@Override public void onMessage(final MessageEvent event) throws Exception { String message = Colors.removeFormattingAndColors(event.getMessage()); if (event.getUser().getNick().equals("SHODAN")) { //Auto Download bot nick if (message.startsWith("Saved")) { // LOAD XML File fXmlFile = new File("Settings.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); NodeList nList = doc.getElementsByTagName("email"); int mailsetting = 0; //NOTE: can setup multiple email profiles for different functions here Node nNode = nList.item(mailsetting); Element eElement = (Element) nNode; //SEND EMAIL STUFF Email email = new SimpleEmail(); email.setHostName(eElement.getElementsByTagName("hostname").item(0).getTextContent()); email.setSmtpPort(465);//from w ww .j av a 2s . c o m email.setAuthenticator( new DefaultAuthenticator(eElement.getElementsByTagName("username").item(0).getTextContent(), eElement.getElementsByTagName("password").item(0).getTextContent())); email.setSSLOnConnect(true); email.setFrom(eElement.getElementsByTagName("from").item(0).getTextContent()); email.setSubject(eElement.getElementsByTagName("subject").item(0).getTextContent()); email.setMsg(message); email.addTo(eElement.getElementsByTagName("to").item(0).getTextContent()); email.send(); event.getBot().sendIRC().message(event.getChannel().getName(), "AAAaaaAAHhhH I just connected to an email server, I feel dirty"); } } }
From source file:sce.Mail.java
public static void sendMail(String subject, String message, String recipient, String headerName, String headerValue) {//from w ww. j a v a 2s. co m try { //load mail settings from quartz.properties Properties prop = new Properties(); prop.load(Mail.class.getResourceAsStream("quartz.properties")); String smtp_hostname = prop.getProperty("smtp_hostname"); int smtp_port = Integer.parseInt(prop.getProperty("smtp_port")); boolean smtp_ssl = prop.getProperty("smtp_ssl").equalsIgnoreCase("true"); String smtp_username = prop.getProperty("smtp_username"); String smtp_password = prop.getProperty("smtp_password"); String smtp_mailfrom = prop.getProperty("smtp_mailfrom"); Email email = new SimpleEmail(); email.setHostName(smtp_hostname); email.setSmtpPort(smtp_port); email.setAuthenticator(new DefaultAuthenticator(smtp_username, smtp_password)); email.setSSLOnConnect(smtp_ssl); email.setFrom(smtp_mailfrom); email.setSubject(subject); email.setMsg(message); String[] recipients = recipient.split(";"); //this is semicolon separated array of recipients for (String tmp : recipients) { email.addTo(tmp); } //email.addHeader(headerName, headerValue); email.send(); } catch (EmailException e) { } catch (IOException e) { } }
From source file:scouter.plugin.server.alert.email.EmailPlugin.java
/** * ? ? ?? <br>/*from ww w.j a v a2 s . c o m*/ * ? ?? ?? <br> * @param pack ?? ? pack */ @ServerPlugin(PluginConstants.PLUGIN_SERVER_ALERT) public void alert(final AlertPack pack) { /* Email */ if (conf.getBoolean("ext_plugin_email_send_alert", true)) { /* * Get log level (0 : INFO, 1 : WARN, 2 : ERROR, 3 : FATAL) * 0 ?? ?? ?. */ int level = conf.getInt("ext_plugin_email_level", 0); /* ? level ? ? ? */ if (level <= pack.level) { new Thread() { public void run() { try { // Get server configurations for email String hostname = conf.getValue("ext_plugin_email_smtp_hostname", "smtp.gmail.com"); // smtp int port = conf.getInt("ext_plugin_email_smtp_port", 587); // smtp ? String username = conf.getValue("ext_plugin_email_username", "haniumscouter@gmail.com"); // ? ?? String password = conf.getValue("ext_plugin_email_password", "dkqorhvk!@#$"); // ? ?? boolean tlsEnabled = conf.getBoolean("ext_plugin_email_tls_enabled", true); // tls (gamil? true) String from = conf.getValue("ext_plugin_email_from_address", "haniumscouter@gmail.com"); // ?? ? ?? String to = conf.getValue("ext_plugin_email_to_address", "occidere@naver.com"); // ? ??(? , ) String cc = conf.getValue("ext_plugin_email_cc_address"); // cc ?? assert hostname != null; assert port > 0; assert username != null; assert password != null; assert from != null; assert to != null; // Get agent Name. ??. String name = AgentManager.getAgentName(pack.objHash) == null ? "N/A" : AgentManager.getAgentName(pack.objHash); if (name.equals("N/A") && pack.message.endsWith("connected.")) { int idx = pack.message.indexOf("connected"); if (pack.message.indexOf("reconnected") > -1) name = pack.message.substring(0, idx - 6); else name = pack.message.substring(0, idx - 4); } // Make email subject String subject = "[" + AlertLevel.getName(pack.level) + "] " + pack.objType.toUpperCase() + "(" + name + ") : " + pack.title; String title = pack.title; String msg = pack.message; /* * Agent ? (inactivate) ? ? . * ? , ? ? Agent ? ? * Agent ? title? ? . */ if (title.equals("INACTIVE_OBJECT")) { title = name + " (Inactivated) ?!"; msg = pack.message.substring(0, pack.message.indexOf("OBJECT") - 1); } //? ? ? ? ? SimpleDateFormat sdf = new SimpleDateFormat("yyyy MM dd? HH mm ss"); // Make email message String message = "[?? ? ver.20170815]" + Util.NEW_LINE + "[ ] : " + title + Util.NEW_LINE + "[ ] : " + sdf.format(new Date(pack.time)) + Util.NEW_LINE + "[ ] : " + pack.objType.toUpperCase() + Util.NEW_LINE + "[? ] : " + name + Util.NEW_LINE + "[ ] : " + AlertLevel.getName(pack.level) + Util.NEW_LINE + "[ ] : " + msg + Util.NEW_LINE; // Create an Email instance Email email = new SimpleEmail(); email.setHostName(hostname); email.setSmtpPort(port); email.setAuthenticator(new DefaultAuthenticator(username, password)); email.setStartTLSEnabled(tlsEnabled); email.setFrom(from); email.setSubject(subject); email.setMsg(message); //? , for (String addr : to.split(",")) { email.addTo(addr); } //cc , if (cc != null) { for (String addr : cc.split(",")) email.addCc(addr); } // Send the email email.send(); println("Email about " + name + " sent to [" + to + "] successfully."); Logger.println("Email about " + name + " sent to [" + to + "] successfully."); } catch (Exception e) { println("[? ] : " + e.getMessage()); Logger.printStackTrace(e); if (conf._trace) { e.printStackTrace(); } } } }.start(); } } }