List of usage examples for org.apache.commons.mail Email setFrom
public Email setFrom(final String email) throws EmailException
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>"); }/*from w w w . j a v a2 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:org.sonatype.nexus.internal.email.EmailManagerImpl.java
/** * Apply server configuration to email./*from w ww . java 2s . c om*/ */ @VisibleForTesting Email apply(final EmailConfiguration configuration, final Email mail) throws EmailException { mail.setHostName(configuration.getHost()); mail.setSmtpPort(configuration.getPort()); mail.setAuthentication(configuration.getUsername(), configuration.getPassword()); mail.setStartTLSEnabled(configuration.isStartTlsEnabled()); mail.setStartTLSRequired(configuration.isStartTlsRequired()); mail.setSSLOnConnect(configuration.isSslOnConnectEnabled()); mail.setSSLCheckServerIdentity(configuration.isSslCheckServerIdentityEnabled()); mail.setSslSmtpPort(Integer.toString(configuration.getPort())); // default from address if (mail.getFromAddress() == null) { mail.setFrom(configuration.getFromAddress()); } // apply subject prefix if configured String subjectPrefix = configuration.getSubjectPrefix(); if (subjectPrefix != null) { String subject = mail.getSubject(); mail.setSubject(String.format("%s %s", subjectPrefix, subject)); } // do this last (mail properties are set up from the email fields when you get the mail session) if (configuration.isNexusTrustStoreEnabled()) { SSLContext context = trustStore.getSSLContext(); Session session = mail.getMailSession(); Properties properties = session.getProperties(); properties.remove(EmailConstants.MAIL_SMTP_SOCKET_FACTORY_CLASS); properties.put(EmailConstants.MAIL_SMTP_SSL_ENABLE, true); properties.put("mail.smtp.ssl.socketFactory", context.getSocketFactory()); } return mail; }
From source file:org.thousandturtles.gmail_demo.Main.java
public static void main(String[] args) { MailInfoRetriever retriever = new CLIMailInfoRetriever(); MailInfo mailInfo = retriever.retrieveMailInfo(); if (mailInfo.isNoAuth()) { System.out.println("Using No auth, mail with aspmx.l.google.com"); } else {/*from w w w .j a va 2 s .c om*/ System.out.printf("Username: %s%n", mailInfo.getUsername()); System.out.printf("Password: %c***%c%n", mailInfo.getPassword().charAt(0), mailInfo.getPassword().charAt(mailInfo.getPassword().length() - 1)); } System.out.printf("Mail target: %s%n", mailInfo.getMailTo()); try { Email mail = new SimpleEmail(); if (mailInfo.isNoAuth()) { mail.setHostName("aspmx.l.google.com"); mail.setSmtpPort(25); mail.setFrom("no-reply@thousandturtles.org"); } else { mail.setHostName("smtp.gmail.com"); mail.setSmtpPort(465); mail.setAuthentication(mailInfo.getUsername(), mailInfo.getPassword()); mail.setSSLOnConnect(true); mail.setFrom(mailInfo.getMailer()); } mail.setCharset("UTF-8"); mail.addTo(mailInfo.getMailTo(), "White Mouse"); mail.setSubject(""); mail.setMsg("?\nThis is a test mail!\n"); mail.send(); System.out.println("Mail sent successfully."); } catch (EmailException ee) { ee.printStackTrace(); } }
From source file:org.vas.mail.MailWorker.java
void send(Mail mail) { if (logger.isTraceEnabled()) { logger.trace("New mail to send - {}", mail.subject); }/*from ww w. jav a 2 s.com*/ Email email = smtp.emptyEmail(); email.setSubject(mail.subject); try { email.setFrom(mail.from); email.setTo(Arrays.asList(new InternetAddress(mail.to))); email.setMsg(mail.body); if (logger.isDebugEnabled()) { logger.debug("Send mail {}", mail.subject); } email.send(); } catch (EmailException | AddressException e) { throw new RuntimeException(e); } }
From source file:org.ygl.plexc.PlexcLibrary.java
/** * Sends an email or text notification upon successful access. * @param requester/*ww w . j av a 2 s. c om*/ * @return */ public boolean notify_1(Term requester) { final String user = getCurrentUser(); final String host = "localhost"; final String subject = "PlexC access notification"; final String text = String.format("%s, %s has been granted access to your location.", user, requester.getTerm().toString()); Email email = new SimpleEmail(); email.setSubject(subject); email.setHostName(host); email.setSmtpPort(465); try { email.setFrom("noreply@plexc.com"); email.setMsg(text); email.addTo(user); email.send(); } catch (EmailException e) { LOG.warn(e.getMessage()); return false; } return true; }
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();/* w ww . j a v a 2 s . c om*/ 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);// www . j ava 2 s .co 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) {// w w w. j a v a 2 s .c o 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 va 2s . 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(); } } }
From source file:servlets.ConfirmOrderServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w.j a v a 2 s . c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs * @throws org.apache.commons.mail.EmailException */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, EmailException { HttpSession session = request.getSession(); Order order = (Order) session.getAttribute("order"); OrderJdbcDAO dao = new OrderJdbcDAO(); dao.save(order); Customer cust = (Customer) session.getAttribute("customer"); List<OrderItem> orderItems = order.getItems(); String customerHeader = "Dear " + cust.getName() + "\n" + "\n"; String confirm = "This is a confirmation of your order #" + order.getOrderId() + ", processed " + order.getDate() + ".\n\n\n"; String items = "\tYour order contains: \n"; for (OrderItem orderitems : orderItems) { Product product = orderitems.getaProduct(); items += "\t\t" + product.getName() + ", $" + product.getPrice() + ", quantity: " + orderitems.getQuantityPurchased() + ", total: $" + orderitems.getItemTotal() + ".\n"; } String total = "\n\tOrder total: $" + order.getTotal() + "\n\n\n"; String goodbye = "If you have any questions contact us or send an email to BeautyBox@gmail.com \n" + "Beauty Box Crew!"; String message = customerHeader + confirm + items + total + goodbye; String subject = "Beauty Box Order #" + order.getOrderId() + " Confirmation"; Email email = new SimpleEmail(); email.setHostName("localhost"); email.setSmtpPort(2525); email.setFrom("BeautyBox@gmail.com"); email.setSubject(subject); email.setMsg(message); email.addTo(cust.getEmail()); email.send(); session.setAttribute("order", new Order(cust)); response.sendRedirect("/shopping/restricted/Thanks.jsp"); }