List of usage examples for org.apache.commons.mail Email addTo
public Email addTo(final String... emails) throws EmailException
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 .ja v a2 s. 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) {/* w ww . j av a 2s .c om*/ 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 w w w . ja v a2 s .c om*/ * ? ?? ?? <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 w ww .j av a 2 s. c o m * * @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"); }
From source file:shnakkydoodle.notifying.endpoints.EmailEndpoint.java
/** * Send the notification// w ww.j a va2 s . c o m * * @param recipient * @param subject * @param message * @throws Exception */ @Override public void send(String recipient, String subject, String message) throws Exception { Email email = null; if (!this.properties.getProperties().containsKey("notification.email.server") || !this.properties.getProperties().containsKey("notification.email.port") || !this.properties.getProperties().containsKey("notification.email.username") || !this.properties.getProperties().containsKey("notification.email.password") || !this.properties.getProperties().containsKey("notification.email.fromemail")) { throw new Exception("Notification email settings incomplete"); } // Determine if we need to send an html or simple email if (message.trim().startsWith("<")) { email = new HtmlEmail(); } else { email = new SimpleEmail(); } email.setHostName(this.properties.getProperties().get("notification.email.server").toString()); email.setSmtpPort( Integer.parseInt(this.properties.getProperties().get("notification.email.port").toString())); email.setAuthentication(this.properties.getProperties().get("notification.email.username").toString(), this.properties.getProperties().get("notification.email.password").toString()); email.setFrom(this.properties.getProperties().get("notification.email.fromemail").toString()); email.setSubject(subject); email.setMsg(message); email.addTo(recipient); email.send(); }
From source file:sk.baka.webvm.analyzer.utils.NotificationDelivery.java
private static void configure(final Email mail, final Config config) throws EmailException { mail.setHostName(config.mailSmtpHost); config.mailSmtpEncryption.activate(mail); if (config.mailSmtpPort > 0) { if (mail.isSSL()) { mail.setSslSmtpPort(Integer.toString(config.mailSmtpPort)); } else {//w w w. j a v a 2s . c o m mail.setSmtpPort(config.mailSmtpPort); } } if (config.mailSmtpUsername != null) { mail.setAuthentication(config.mailSmtpUsername, config.mailSmtpPassword); } mail.setFrom(config.mailFrom); if (config.mailTo == null) { config.mailTo = ""; } // add recipients final StringTokenizer t = new StringTokenizer(config.mailTo, ","); for (; t.hasMoreTokens();) { mail.addTo(t.nextToken().trim()); } }
From source file:uap.workflow.engine.bpmn.behavior.MailActivityBehavior.java
protected void addTo(Email email, String to) { String[] tos = splitAndTrim(to); if (tos != null) { for (String t : tos) { try { email.addTo(t); } catch (EmailException e) { throw new WorkflowException("Could not add " + t + " as recipient", e); }// w w w . j a v a 2 s . c o m } } else { throw new WorkflowException("No recipient could be found for sending email"); } }
From source file:velo.ejb.impl.EmailBean.java
public void sendEmailsToApproversGroup(String agUniqueName, String emailTemplateName, Map<String, Object> varsMap) throws EmailNotificationException { ApproversGroup ag = approversGroupManager.findApproversGroup(agUniqueName); if (ag == null) { throw new EmailNotificationException("Could not find Approvers Group with name '" + agUniqueName + "'"); }/*from w w w . j a v a2 s .co m*/ EmailTemplate et = findEmailTemplate(emailTemplateName); if (et == null) { throw new EmailNotificationException( "Could not find Email Template with name '" + emailTemplateName + "'"); } InitialContext ctx = null; TransactionManager tm = null; try { ctx = new InitialContext(); tm = (TransactionManager) ctx.lookup("java:/TransactionManager"); } catch (Exception e) { e.printStackTrace(); } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { } } } /* try { System.out.println("!!!!!!!!!!!!!!!zzzzzzzzzzZ2: " + tm.getStatus()); System.out.println("!!!!!!!!!!!!!!!Zzzzzzzzzz2: " + tm.getTransaction().getStatus()); }catch(SystemException e) { e.printStackTrace(); } */ //throw new EmailNotificationException("ERROR ERROR ERROR!"); et.setContentVars(varsMap); EdmEmailSender es = new EdmEmailSender(); Email email = null; try { email = es.factoryEmail(et.getSubject(), et.getParsedContent()); //email.addTo("asaf@mydomain.com"); //email.send(); } catch (EmailException e) { log.error("Could not factory email objecT: " + e.getMessage()); throw new EmailNotificationException(e); } catch (ExpressionCreationException e) { log.error("Could parsing email content: " + e.getMessage()); throw new EmailNotificationException(e); } for (User currUser : ag.getApprovers()) { try { if (Generic.isEmailValid(currUser.getEmail())) { email.addTo(currUser.getEmail()); } else { log.warn("The specified email address is not valid, skipping email: " + currUser.getEmail()); } } catch (EmailException e) { log.error("Could not send email to user: " + currUser.getName() + " (email address: '" + currUser.getEmail() + "'), part of ApproversGroup '" + ag.getDescription() + "' due to: " + e.getMessage()); } } try { email.send(); } catch (EmailException e) { throw new EmailNotificationException(e); } }
From source file:velo.ejb.impl.EmailBean.java
public void sendEmailToUser(String userName, String emailTemplateName, Map<String, Object> varsMap) throws EmailNotificationException { EmailTemplate et = findEmailTemplate(emailTemplateName); if (et == null) { throw new EmailNotificationException( "Could not find Email Template with name '" + emailTemplateName + "'"); }/* w w w .j a v a2s. c o m*/ et.setContentVars(varsMap); User user = userManager.findUser(userName); if (user == null) { throw new EmailNotificationException("Could not find User name '" + emailTemplateName + "'"); } EdmEmailSender es = new EdmEmailSender(); Email email = null; try { email = es.factoryEmail(et.getSubject(), et.getParsedContent()); } catch (EmailException e) { log.error("Could not factory email objecT: " + e.getMessage()); throw new EmailNotificationException(e); } catch (ExpressionCreationException e) { log.error("Could parsing email content: " + e.getMessage()); throw new EmailNotificationException(e); } try { email.addTo(user.getEmail()); } catch (EmailException e) { log.error("Could not send email to user: " + user.getName() + " (email address: '" + user.getEmail() + "')" + "' due to: " + e.getMessage()); } try { email.send(); } catch (EmailException e) { throw new EmailNotificationException(e); } }
From source file:velo.ejb.seam.action.SelfServiceAccessRequestActionsBean.java
private void notifyApproverUponNewApprovalTask(SelfServiceAccessRequest request, int level) { EmailTemplate et = emailManager.findEmailTemplate(approverNewApprovalTaskEmailTemplateName); if (et == null) { log.warn("Could not send mail, expected email template named #0 does not exist", approverNewApprovalTaskEmailTemplateName); return;/* w w w .j a va 2 s . c om*/ } EdmEmailSender ees = new EdmEmailSender(); et.addContentVar("requester", request.getRequester()); et.addContentVar("request", request); String parsedContent = null; for (User currApprover : request.getApprovers(level)) { et.addContentVar("approver", currApprover); try { parsedContent = et.getParsedContent(); } catch (ExpressionCreationException e) { log.warn("Could not parse expressions in email template #0: #1", et.getName(), e.toString()); log.warn("Continuing to notify the next approver..."); continue; } try { Email email = ees.factoryEmail(et.getSubject(), parsedContent); String currApproversEmailAddress = currApprover.getEmail(); if (currApproversEmailAddress != null) { email.addTo(currApproversEmailAddress); ees.addEmail(email); } else { log.info("Approver #0 has no email address, skipping approver notification...", currApprover.getName()); } } catch (EmailException e) { log.info("Skipping approver '#0' notification: #1", currApprover.getName(), e.toString()); } } log.debug("Prepared #0 amount of emails to send, sending mails..."); ees.send(); }