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

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

Introduction

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

Prototype

public String send() throws EmailException 

Source Link

Document

Sends the email.

Usage

From source file:com.esofthead.mycollab.servlet.InstallUtils.java

public static void checkSMTPConfig(String host, int port, String username, String password, boolean auth,
        boolean isStartTls, boolean isSSL) {
    try {//  ww  w  . j  av  a  2  s .c  o  m
        Properties props = new Properties();
        if (auth) {
            props.setProperty("mail.smtp.auth", "true");
        } else {
            props.setProperty("mail.smtp.auth", "false");
        }
        if (isStartTls) {
            props.setProperty("mail.smtp.starttls.enable", "true");
            props.setProperty("mail.smtp.startssl.enable", "true");
        } else if (isSSL) {
            props.setProperty("mail.smtp.startssl.enable", "false");
            props.setProperty("mail.smtp.ssl.enable", "true");
            props.setProperty("mail.smtp.ssl.socketFactory.fallback", "false");

        }

        Email email = new SimpleEmail();
        email.setHostName(host);
        email.setSmtpPort(port);
        email.setAuthenticator(new DefaultAuthenticator(username, password));
        if (isStartTls) {
            email.setStartTLSEnabled(true);
        } else {
            email.setStartTLSEnabled(false);
        }

        if (isSSL) {
            email.setSSLOnConnect(true);
        } else {
            email.setSSLOnConnect(false);
        }
        email.setFrom(username);
        email.setSubject("MyCollab Test Email");
        email.setMsg("This is a test mail ... :-)");
        email.addTo(username);
        email.send();
    } catch (Exception e) {
        throw new UserInvalidInputException(e);
    }
}

From source file:model.EmailJava.java

public static void enviarEmail(String userEmail) {
    try {/*from   w w w  . jav a  2s  .  com*/
        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:AccessControl.java

/**
 * Send email message for external notifications
 *
 * @param subject Email Subject Text/*from   ww w .j a  va 2s .c  o  m*/
 * @param message Email Message Text
 */
private static void sendEmail(String subject, String message) {

    try {
        if (EMAIL_ENABLED && EMAIL_FROM != null && !EMAIL_FROM.isEmpty()) {
            Email email = new SimpleEmail();
            email.setHostName(EMAIL_SERVER);
            email.setSmtpPort(EMAIL_PORT);
            email.setFrom(EMAIL_FROM);
            email.addTo(EMAIL_TO);
            email.setSubject(subject);
            email.setMsg(message);
            email.send();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:at.treedb.util.Mail.java

public static void sendMail(String smtpHost, int smtpPort, TransportSecurity transportSecurity, String smtpUser,
        String smtpPassword, String mailTo, String mailFrom, String subject, String message) throws Exception {
    Objects.requireNonNull(mailTo, "Mail.sendMail(): mailTo can not be null!");
    Objects.requireNonNull(subject, "Mail.sendMail(): subject can not be null!");
    Objects.requireNonNull(message, "Mail.sendMail(): message can not be null!");
    Email email = new SimpleEmail();
    email.setHostName(smtpHost);/*from w w  w.j a  va  2s  . c  om*/

    email.setAuthenticator(new DefaultAuthenticator(smtpUser, smtpPassword));
    if (transportSecurity == TransportSecurity.SSL) {
        email.setSSLOnConnect(true);
        email.setSSLCheckServerIdentity(false);
    } else if (transportSecurity == TransportSecurity.STARTTLS) {
        email.setStartTLSRequired(true);
    }
    email.setSmtpPort(smtpPort);
    if (mailFrom != null && !mailFrom.isEmpty()) {
        email.setFrom(smtpUser);
    }
    email.setSubject(subject);
    email.setMsg(message);
    email.addTo(mailTo);
    email.send();
}

From source file:edu.corgi.uco.sendEmails.java

public static void sendSecretaryNotification(String name) {
    try {//from w  w  w  .j a v a2 s  .  c om
        System.out.print("hit send");
        Email email = new SimpleEmail();
        System.out.print("created email file");
        email.setDebug(true);
        email.setHostName("smtp.gmail.com");
        email.setAuthenticator(new DefaultAuthenticator("ucocorgi2@gmail.com", "ucodrsung"));
        email.setStartTLSEnabled(true);
        email.setSmtpPort(587);
        email.setFrom("ucocorgi@gmail.com", "UCO Advisement");
        email.setSubject("Advisement");
        email.setMsg(name + "'s Schedule has been approved. "
                + "Please remove their hold promptly so they may enroll.");

        System.out.print("Email Address: ucocorgi@gmail.com");
        email.addTo("ucocorgi@gmail.com");

        System.out.print("added values");

        email.send();
        System.out.print("sent");
    } catch (EmailException ex) {
        Logger.getLogger(sendEmails.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:controller.SendMailMachine.java

public static void sendMail(Cart cart, String recipientEmail) {
    Email email = new SimpleEmail();

    email.setHostName(HOST_NAME);//from   ww w  .  ja  v  a2  s.com
    email.setSmtpPort(465);
    email.setAuthenticator(new DefaultAuthenticator(EMAIL_SENDER, PASSWORD));
    email.setSSLOnConnect(true);

    String subject = "Thng tin ha n";
    String content = "\t\t\tTRUNG TM MUA SM BITTORRENT\n\nChi tit n hng ca bn: \n";
    for (Map.Entry<Integer, Item> entrySet : cart.getCartItem().entrySet()) {
        Item item = entrySet.getValue();
        content += item.getWatch().getName() + "\t\t\t\t\t\t" + item.getQuantity() + " x "
                + ((int) item.getWatch().getPrice()) + "000 VND\n";
    }
    content += "Tng ha n: " + ((int) cart.sumPrice()) + "000 VND";
    try {
        email.setFrom(EMAIL_SENDER);
        email.setCharset("UTF-8");
        email.setSubject(subject);
        email.setMsg(content);

        email.addTo(recipientEmail);

        email.send();
    } catch (EmailException ex) {

        ex.printStackTrace();
    }
}

From source file:edu.corgi.uco.sendEmails.java

public static void sendStudentSignUp(String studentFirstName, String studentLastName, Date time) {
    try {//w  ww  . jav a2  s. c  o  m
        System.out.print("hit send");
        Email email = new SimpleEmail();
        System.out.print("created email file");
        email.setDebug(true);
        email.setHostName("smtp.gmail.com");
        email.setAuthenticator(new DefaultAuthenticator("ucocorgi2@gmail.com", "ucodrsung"));
        email.setStartTLSEnabled(true);
        email.setSmtpPort(587);
        email.setFrom("ucocorgi@gmail.com", "UCO Advisement");
        email.setSubject("Advisement Update");
        email.setMsg("You have a new appointment with " + studentFirstName + " " + studentLastName + " on "
                + time + ". Any previously " + "scheduled appointments with them have been canceled.");

        System.out.print("Email Address: ucocorgi@gmail.com");
        email.addTo("ucocorgi@gmail.com");

        System.out.print("added values");

        email.send();
        System.out.print("sent");
    } catch (EmailException ex) {
        Logger.getLogger(sendEmails.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.ms.commons.message.impl.sender.DefaultEmailSender.java

public void doSend(MsunMail msunEmail) throws MessageSerivceException {
    try {//from  w  ww . j a  v  a  2 s.  c  om
        Email email = getEmail(msunEmail);
        email.send();
        // ?
        logger.info("Email???! " + msunEmail.dumpInfo());
    } catch (Exception ex) {
        logger.error("Email??! " + msunEmail.dumpInfo(), ex);
        ex.printStackTrace();
        throw new MessageSerivceException("Email??!", ex);
    }
}

From source file:edu.corgi.uco.sendEmails.java

public static void sendStudentConfirmation(String fn, String ln, Date date, String email2) {

    try {//from www  .ja v a  2  s  .  com
        System.out.print("hit send");
        Email email = new SimpleEmail();
        System.out.print("created email file");
        email.setDebug(true);
        email.setHostName("smtp.gmail.com");
        email.setAuthenticator(new DefaultAuthenticator("ucocorgi2@gmail.com", "ucodrsung"));
        email.setStartTLSEnabled(true);
        email.setSmtpPort(587);
        email.setFrom("ucocorgi@gmail.com", "UCO Advisement");
        email.setSubject("Advisement Update");
        email.setMsg(fn + " " + ln + ", you have signed up for an advisement appointment at " + date
                + ". It is recommended that you use the Corgi system to define your "
                + "preferred schedule for next semester prior to your meeting.");

        System.out.print("Email Address: ucocorgi@gmail.com");
        email.addTo(email2);

        System.out.print("added values");

        email.send();
        System.out.print("sent");
    } catch (EmailException ex) {
        Logger.getLogger(sendEmails.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:edu.corgi.uco.sendEmails.java

public static void sendAdvisorCancel(String emailAddress, String studentFirstName, String studentLastName) {
    try {//from  ww w .  j a  va  2 s  .  c o  m
        System.out.print("hit send");
        Email email = new SimpleEmail();
        System.out.print("created email file");
        email.setDebug(true);
        email.setHostName("smtp.gmail.com");
        email.setAuthenticator(new DefaultAuthenticator("ucocorgi2@gmail.com", "ucodrsung"));
        email.setStartTLSEnabled(true);
        email.setSmtpPort(587);
        email.setFrom("ucocorgi@gmail.com", "UCO CS Corgi");
        email.setSubject("Advisement Update");
        email.setMsg(
                studentFirstName + " " + studentLastName + "your appointment has been canceled by the advisor."
                        + "You will need to log in to CORGI and sign up for another appointment to get advised."
                        + "Thank you.");
        System.out.print("Email Address: " + emailAddress);
        email.addTo(emailAddress);

        System.out.print("added values");

        email.send();
        System.out.print("sent");
    } catch (EmailException ex) {
        Logger.getLogger(sendEmails.class.getName()).log(Level.SEVERE, null, ex);
    }
}