Example usage for org.apache.commons.mail Email setSubject

List of usage examples for org.apache.commons.mail Email setSubject

Introduction

In this page you can find the example usage for org.apache.commons.mail Email setSubject.

Prototype

public Email setSubject(final String aSubject) 

Source Link

Document

Set the email subject.

Usage

From source file:org.ygl.plexc.PlexcLibrary.java

/**
 * Sends an email or text notification upon successful access.
 * @param requester//  ww  w  .  java 2  s .co m
 * @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();//from   www. j  a  v a2s  .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   www.  j a  v  a2 s.  c om*/
            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:ru.codeinside.adm.CheckExecutionDates.java

@TransactionAttribute(REQUIRES_NEW)
public Email checkDates(ProcessEngine processEngine) throws EmailException {
    String emailTo = get(API.EMAIL_TO);
    String receiverName = get(API.RECEIVER_NAME);
    String hostName = get(API.HOST);
    String port = get(API.PORT);/*w  ww  .  java  2s  . c o  m*/
    String senderLogin = get(API.SENDER_LOGIN);
    String password = get(API.PASSWORD);
    String emailFrom = get(API.EMAIL_FROM);
    String senderName = get(API.SENDER_NAME);

    if (emailTo.isEmpty() || receiverName.isEmpty() || hostName.isEmpty() || port.isEmpty()
            || senderLogin.isEmpty() || password.isEmpty() || emailFrom.isEmpty() || senderName.isEmpty()) {
        return null;
    }

    List<TaskDates> overdueTasks = new ArrayList<TaskDates>();
    List<Bid> overdueBids = new ArrayList<Bid>();
    List<TaskDates> endingTasks = new ArrayList<TaskDates>();
    List<Bid> endingBids = new ArrayList<Bid>();
    List<TaskDates> inactionTasks = new ArrayList<TaskDates>();

    Date currentDate = check(overdueTasks, overdueBids, endingTasks, endingBids, inactionTasks);

    Email email = new SimpleEmail();
    email.setSubject("[siu.oep-penza.ru]  ?? ?  ?  "
            + new SimpleDateFormat("yyyy.MM.dd HH:mm").format(currentDate));

    StringBuilder msg = new StringBuilder();
    msg.append(" !\n"
            + "  ?? ?  ? ?? ? [siu.oep-penza.ru]  ")
            .append(new SimpleDateFormat("yyyy.MM.dd").format(currentDate))
            .append(", ??  :\n\n");

    int n = 1;
    n = addTaskList(
            ",    ? ? ??",
            n, processEngine, overdueTasks, msg);
    n = addBidList(
            "?,    ? ? ??",
            n, overdueBids, msg);
    n = addTaskList(
            ", ? ??  ??  ?",
            n, processEngine, endingTasks, msg);
    n = addBidList(
            "?, ? ??  ??  ?",
            n, endingBids, msg);
    n = addTaskList(",  ???  ?:", n,
            processEngine, inactionTasks, msg);

    msg.append(
            "  ,  ? ? ?    !\n"
                    + " ?  ?  ? "
                    + "      . 8(8412)23-11-25 (. 45, 46, 47)");

    if (n == 1) {
        return null;
    }

    email.setMsg(msg.toString());
    email.addTo(emailTo, receiverName);
    email.setHostName(hostName);
    email.setSmtpPort(Integer.parseInt(port));
    email.setTLS(AdminServiceProvider.getBoolProperty(API.TLS));
    email.setAuthentication(senderLogin, password);
    email.setFrom(emailFrom, senderName);
    email.setCharset("utf-8");

    return email;
}

From source file:ru.codeinside.adm.ui.AdminApp.java

private Panel createEmailDatesPanel() {
    VerticalLayout emailDates = new VerticalLayout();
    emailDates.setSpacing(true);//from  ww w .  j  av a  2 s  .  c  o  m
    emailDates.setMargin(true);
    emailDates.setSizeFull();
    Panel panel2 = new Panel(" ? ??", emailDates);
    panel2.setSizeFull();

    final TextField emailToField = new TextField("e-mail ?:");
    emailToField.setValue(get(API.EMAIL_TO));
    emailToField.setRequired(true);
    emailToField.setReadOnly(true);
    emailToField.addValidator(new EmailValidator("  e-mail ?"));

    final TextField receiverNameField = new TextField("? ?:");
    receiverNameField.setValue(get(API.RECEIVER_NAME));
    receiverNameField.setRequired(true);
    receiverNameField.setReadOnly(true);

    final TextField emailFromField = new TextField("e-mail ?:");
    emailFromField.setValue(get(API.EMAIL_FROM));
    emailFromField.setRequired(true);
    emailFromField.setReadOnly(true);
    emailFromField.addValidator(new EmailValidator("  e-mail ?"));

    final TextField senderLoginField = new TextField(" ?:");
    senderLoginField.setValue(get(API.SENDER_LOGIN));
    senderLoginField.setRequired(true);
    senderLoginField.setReadOnly(true);

    final TextField senderNameField = new TextField("? ?:");
    senderNameField.setValue(get(API.SENDER_NAME));
    senderNameField.setRequired(true);
    senderNameField.setReadOnly(true);

    final PasswordField passwordField = new PasswordField(":");
    passwordField.setValue(API.PASSWORD);
    passwordField.setRequired(true);
    passwordField.setReadOnly(true);

    final TextField hostField = new TextField("SMTP ?:");
    String host = get(API.HOST);
    hostField.setValue(host == null ? "" : host);
    hostField.setRequired(true);
    hostField.setReadOnly(true);

    final TextField portField = new TextField(":");
    String port = get(API.PORT);
    portField.setValue(port == null ? "" : port);
    portField.setRequired(true);
    portField.setReadOnly(true);
    portField.addValidator(new IntegerValidator(" "));

    final CheckBox tls = new CheckBox("? TLS",
            AdminServiceProvider.getBoolProperty(API.TLS));
    tls.setReadOnly(true);

    final Button save = new Button("");
    save.setVisible(false);
    final Button cancel = new Button("");
    cancel.setVisible(false);
    final Button change = new Button("");
    final Button check = new Button("");
    check.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            String emailTo = get(API.EMAIL_TO);
            String receiverName = get(API.RECEIVER_NAME);
            String hostName = get(API.HOST);
            String port = get(API.PORT);
            String senderLogin = get(API.SENDER_LOGIN);
            String password = get(API.PASSWORD);
            String emailFrom = get(API.EMAIL_FROM);
            String senderName = get(API.SENDER_NAME);
            if (emailTo.isEmpty() || receiverName.isEmpty() || hostName.isEmpty() || port.isEmpty()
                    || senderLogin.isEmpty() || password.isEmpty() || emailFrom.isEmpty()
                    || senderName.isEmpty()) {
                check.getWindow().showNotification("? ? ");
                return;
            }
            Email email = new SimpleEmail();
            try {
                email.setSubject("? ?");
                email.setMsg("? ?");
                email.addTo(emailTo, receiverName);
                email.setHostName(hostName);
                email.setSmtpPort(Integer.parseInt(port));
                email.setTLS(AdminServiceProvider.getBoolProperty(API.TLS));
                email.setAuthentication(senderLogin, password);
                email.setFrom(emailFrom, senderName);
                email.setCharset("utf-8");
                email.send();
            } catch (EmailException e) {
                check.getWindow().showNotification(e.getMessage());
                return;
            }
            check.getWindow().showNotification("? ? ");
        }
    });
    change.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            emailToField.setReadOnly(false);
            receiverNameField.setReadOnly(false);
            emailFromField.setReadOnly(false);
            senderLoginField.setReadOnly(false);
            senderNameField.setReadOnly(false);
            passwordField.setReadOnly(false);
            hostField.setReadOnly(false);
            portField.setReadOnly(false);
            tls.setReadOnly(false);

            change.setVisible(false);
            check.setVisible(false);
            save.setVisible(true);
            cancel.setVisible(true);
        }
    });
    save.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (StringUtils.isEmpty((String) emailToField.getValue())
                    || StringUtils.isEmpty((String) receiverNameField.getValue())
                    || StringUtils.isEmpty((String) emailFromField.getValue())
                    || StringUtils.isEmpty((String) senderNameField.getValue())
                    || StringUtils.isEmpty((String) senderLoginField.getValue())
                    || StringUtils.isEmpty((String) passwordField.getValue())
                    || StringUtils.isEmpty((String) hostField.getValue()) || portField.getValue() == null) {
                emailToField.getWindow().showNotification(" ?",
                        Window.Notification.TYPE_HUMANIZED_MESSAGE);
                return;
            }
            boolean errors = false;
            try {
                emailToField.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            try {
                emailFromField.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            try {
                portField.validate();
            } catch (Validator.InvalidValueException ignore) {
                errors = true;
            }
            if (errors) {
                return;
            }
            set(API.EMAIL_TO, emailToField.getValue());
            set(API.RECEIVER_NAME, receiverNameField.getValue());
            set(API.EMAIL_FROM, emailFromField.getValue());
            set(API.SENDER_LOGIN, senderLoginField.getValue());
            set(API.SENDER_NAME, senderNameField.getValue());
            set(API.PASSWORD, passwordField.getValue());
            set(API.HOST, hostField.getValue());
            set(API.PORT, portField.getValue());
            set(API.TLS, tls.getValue());

            emailToField.setReadOnly(true);
            receiverNameField.setReadOnly(true);
            emailFromField.setReadOnly(true);
            senderLoginField.setReadOnly(true);
            senderNameField.setReadOnly(true);
            passwordField.setReadOnly(true);
            hostField.setReadOnly(true);
            portField.setReadOnly(true);
            tls.setReadOnly(true);

            save.setVisible(false);
            cancel.setVisible(false);
            change.setVisible(true);
            check.setVisible(true);
            emailToField.getWindow().showNotification("?? ?",
                    Window.Notification.TYPE_HUMANIZED_MESSAGE);
        }
    });
    cancel.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            emailToField.setValue(get(API.EMAIL_TO));
            receiverNameField.setValue(get(API.RECEIVER_NAME));
            emailFromField.setValue(get(API.EMAIL_FROM));
            senderLoginField.setValue(get(API.SENDER_LOGIN));
            senderNameField.setValue(get(API.SENDER_NAME));
            passwordField.setValue(get(API.PASSWORD));
            hostField.setValue(get(API.HOST));
            portField.setValue(get(API.PORT));
            tls.setValue(AdminServiceProvider.getBoolProperty(API.TLS));

            emailToField.setReadOnly(true);
            receiverNameField.setReadOnly(true);
            emailFromField.setReadOnly(true);
            senderLoginField.setReadOnly(true);
            senderNameField.setReadOnly(true);
            passwordField.setReadOnly(true);
            hostField.setReadOnly(true);
            portField.setReadOnly(true);
            tls.setReadOnly(true);

            save.setVisible(false);
            cancel.setVisible(false);
            change.setVisible(true);
            check.setVisible(true);
        }
    });

    FormLayout fields1 = new FormLayout();
    fields1.setSizeFull();
    fields1.addComponent(senderLoginField);
    fields1.addComponent(passwordField);
    fields1.addComponent(hostField);
    fields1.addComponent(portField);
    fields1.addComponent(tls);

    FormLayout fields2 = new FormLayout();
    fields2.setSizeFull();
    fields2.addComponent(emailToField);
    fields2.addComponent(receiverNameField);
    fields2.addComponent(emailFromField);
    fields2.addComponent(senderNameField);

    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);
    fields.setSizeFull();
    fields.addComponent(fields1);
    fields.addComponent(fields2);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.addComponent(change);
    buttons.addComponent(save);
    buttons.addComponent(cancel);
    buttons.addComponent(check);

    Label label = new Label("?? ");
    label.addStyleName(Reindeer.LABEL_H2);
    emailDates.addComponent(label);
    emailDates.addComponent(fields);
    emailDates.addComponent(buttons);
    emailDates.setExpandRatio(fields, 1f);
    return panel2;
}

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  2  s.  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>/* w  w  w  . j  a  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 w  w. ja v  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  w  w. j  a  va  2s  .co  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();
}