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

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

Introduction

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

Prototype

public Email setSSLOnConnect(final boolean ssl) 

Source Link

Document

Sets whether SSL/TLS encryption should be enabled for the SMTP transport upon connection (SMTPS/POPS).

Usage

From source file:br.fgv.util.EmailSender.java

public static void enviarEmail(String body, String subject) throws EmailException {

    StringBuffer sb = new StringBuffer("");
    sb.append(body);//from  ww w  .j  av  a2 s.com

    Email email = new SimpleEmail();
    email.setHostName("smtp.gmail.com");

    email.setDebug(true);
    email.setSSLOnConnect(true);

    email.addTo("wesley.seidel@gmail.com");

    email.setAuthentication("wseidel.fgv", "batavinhofgv");

    email.setFrom("wseidel.fgv@gmail.com");
    email.setSubject(subject);
    email.setMsg(sb.toString());

    email.send();
}

From source file:io.jhonesdeveloper.swing.util.EmailUtil.java

public static void sendBasicText(String hostName, String username, String password, String from, String subject,
        String msg, String[] to) throws EmailException {
    Email email = new SimpleEmail();
    email.setHostName(hostName);/*from  ww w .  j  a  va 2 s.  c  om*/
    email.setSmtpPort(465);
    email.setAuthenticator(new DefaultAuthenticator(username, password));
    email.setSSLOnConnect(true);
    email.setFrom(from);
    email.setSubject(subject);
    email.setMsg(msg);
    email.addTo(to);
    email.send();
}

From source file:at.tugraz.kmi.medokyservice.ErrorLogNotifier.java

public static void errorEmail(String msg) {

    Email email = new SimpleEmail();
    email.setHostName("something.com");
    email.setSmtpPort(465);// w ww .  j  av  a  2 s  .  c om
    DefaultAuthenticator auth = new DefaultAuthenticator("username", "pwd");
    email.setAuthenticator(auth);
    email.setSSLOnConnect(true);
    try {
        email.setFrom("email address");
        email.setSubject("[MEDoKyService] Error");
        email.setMsg(msg);
        email.addTo("yourmail.com");
        email.send();
    } catch (EmailException e) {
        e.printStackTrace();
    }

}

From source file:controller.SendMailMachine.java

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

    email.setHostName(HOST_NAME);/*from w w w . j  a  v a 2s. c  o  m*/
    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:connection.EmailSending.java

public static void sendTextEmail(String subject, String content, String recipientEmail) {
    Email email = new SimpleEmail();

    email.setHostName(MailInfor.HOST_NAME);
    email.setSmtpPort(465);//from  ww  w  . j av a  2  s  .c  o m
    email.setAuthenticator(new DefaultAuthenticator(MailInfor.EMAIL_SENDER, MailInfor.PASSWORD));
    email.setSSLOnConnect(true);

    try {
        email.setFrom(MailInfor.EMAIL_SENDER);
        email.setSubject(subject);
        email.setMsg(content);
        email.addTo(recipientEmail);

        email.send();
    } catch (EmailException ex) {
        Logger.getLogger(EmailSending.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:model.EmailJava.java

public static void enviarEmail(String userEmail) {
    try {//  w  ww.j a  va 2 s.  c o  m
        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:com.github.triceo.robozonky.notifications.email.AbstractEmailingListener.java

private static Email createNewEmail(final EmailNotificationProperties properties) throws EmailException {
    final Email email = new SimpleEmail();
    email.setCharset(Defaults.CHARSET.displayName());
    email.setHostName(properties.getSmtpHostname());
    email.setSmtpPort(properties.getSmtpPort());
    email.setStartTLSRequired(properties.isStartTlsRequired());
    email.setSSLOnConnect(properties.isSslOnConnectRequired());
    email.setAuthentication(properties.getSmtpUsername(), properties.getSmtpPassword());
    email.setFrom(properties.getSender(), "RoboZonky @ " + properties.getLocalHostAddress());
    email.addTo(properties.getRecipient());
    return email;
}

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);/* w  ww.j a  va 2s  .  c  o m*/

    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: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:FacultyAdvisement.StudentRepository.java

public static void adminUpdate(DataSource ds, Student student, String oldUsername) throws SQLException {
    Connection conn = ds.getConnection();
    if (conn == null) {
        throw new SQLException("conn is null; Can't get db connection");
    }//from  ww  w.  jav a  2 s  .c  o  m
    try {

        PreparedStatement ps;
        ps = conn.prepareStatement(
                "Update STUDENT set EMAIL=?, FIRSTNAME=?, LASTNAME=?, MAJORCODE=?, PHONE=?, ADVISED=? where STUID=?");
        ps.setString(1, student.getUsername());
        ps.setString(2, student.getFirstName());
        ps.setString(3, student.getLastName());
        ps.setString(4, student.getMajorCode());
        ps.setString(5, student.getPhoneNumber());
        if (student.isAdvised()) {
            ps.setString(6, "true");
        } else {
            ps.setString(6, "false");
        }
        ps.setString(7, student.getId());
        ps.executeUpdate();

        ps = conn.prepareStatement("Update USERTABLE set USERNAME=? where USERNAME=?");
        ps.setString(1, student.getUsername());
        ps.setString(2, oldUsername);
        ps.executeUpdate();

        ps = conn.prepareStatement("Update GROUPTABLE set USERNAME=? where USERNAME=?");
        ps.setString(1, student.getUsername());
        ps.setString(2, oldUsername);
        ps.executeUpdate();

        if (student.isResetPassword()) {
            String newPassword = UUID.randomUUID().toString();
            String encryptedPassword = SHA256Encrypt.encrypt(newPassword);
            ps = conn.prepareStatement("Update USERTABLE set PASSWORD=? where USERNAME=?");
            ps.setString(1, encryptedPassword);
            ps.setString(2, student.getUsername());
            ps.executeUpdate();

            Email email = new HtmlEmail();
            email.setHostName("smtp.googlemail.com");
            email.setSmtpPort(465);
            email.setAuthenticator(new DefaultAuthenticator("uco.faculty.advisement", "!@#$1234"));
            email.setSSLOnConnect(true);
            email.setFrom("uco.faculty.advisement@gmail.com");
            email.setSubject("UCO Faculty Advisement Password Change");
            email.setMsg("<font size=\"3\">An admin has resetted your password, your new password is \""
                    + newPassword + "\"." + "\n<p align=\"center\">UCO Faculty Advisement</p></font>");
            email.addTo(student.getUsername());
            email.send();

        }

    } catch (EmailException ex) {
        Logger.getLogger(StudentRepository.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        conn.close();
    }

    //students = (HashMap<String, StudentPOJO>) readAll(); // reload the updated info
}