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

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

Introduction

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

Prototype

public Email setStartTLSEnabled(final boolean startTlsEnabled) 

Source Link

Document

Set or disable the STARTTLS encryption.

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 {//from  ww  w  .  j a v a 2  s . c  om
        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:edu.corgi.uco.sendEmails.java

public static void sendStudentSignUp(String studentFirstName, String studentLastName, Date time) {
    try {/* ww  w.  j a v a2s .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:edu.corgi.uco.sendEmails.java

public static void sendSecretaryNotification(String name) {
    try {/*w  w  w. j a v a  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 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:edu.corgi.uco.sendEmails.java

public static void sendAdvisorCancel(String emailAddress, String studentFirstName, String studentLastName) {
    try {/*w w w  .j  a  v  a 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);
    }
}

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

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

    try {/*from w w  w  .  jav  a  2s  .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(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:net.sasasin.sreader.batch.publish.GMailPublisher.java

@Override
public void publish(ContentViewId content) {
    try {/*from w w w  . jav  a 2s. c  o  m*/
        Email email = new SimpleEmail();
        email.setHostName("smtp.gmail.com");
        email.setSmtpPort(587);
        email.setStartTLSEnabled(true);
        email.setCharset("UTF-8");

        email.setAuthenticator(new DefaultAuthenticator(content.getEmail(), content.getPassword()));

        email.setFrom(content.getEmail());
        email.addTo(content.getEmail());
        email.setSubject(content.getTitle());
        email.setMsg(content.getUrl() + "\n" + content.getFullText());

        email.send();
        log(content);
    } catch (EmailException e) {
        e.printStackTrace();
    }
}

From source file:com.qwazr.connectors.EmailConnector.java

public void sendEmail(Email email) throws EmailException {
    email.setHostName(hostname);/*from  w  w w  .jav  a 2  s  .  co  m*/
    if (ssl != null)
        email.setSSLOnConnect(ssl);
    if (start_tls_enabled != null)
        email.setStartTLSEnabled(start_tls_enabled);
    if (start_tls_required != null)
        email.setStartTLSRequired(start_tls_required);
    if (port != null)
        email.setSmtpPort(port);
    if (username != null)
        email.setAuthentication(username, password);
    if (connection_timeout != null)
        email.setSocketConnectionTimeout(connection_timeout);
    if (timeout != null)
        email.setSocketTimeout(timeout);
    email.send();
}

From source file:com.qwazr.library.email.EmailConnector.java

public void sendEmail(final Email email) throws EmailException {
    email.setHostName(hostname);/*from w w w  .  ja  v a  2  s . c  o m*/
    if (ssl != null)
        email.setSSLOnConnect(ssl);
    if (start_tls_enabled != null)
        email.setStartTLSEnabled(start_tls_enabled);
    if (start_tls_required != null)
        email.setStartTLSRequired(start_tls_required);
    if (port != null)
        email.setSmtpPort(port);
    if (username != null)
        email.setAuthentication(username, password);
    if (connection_timeout != null)
        email.setSocketConnectionTimeout(connection_timeout);
    if (timeout != null)
        email.setSocketTimeout(timeout);
    email.send();
}

From source file:edu.br.tcc.ManagedBean.TrabalhosBean.java

public Formulario enviarEmail(Formulario trabalho) {
    System.out.println("entrou no metodo do mb enviarEmail");
    try {//from ww w .  j  av  a2  s  .c  om
        System.out.println("teste: " + trabalho.getEmail());

        Email emailSimples = new SimpleEmail();

        emailSimples.setHostName("smtp.live.com");
        emailSimples.setStartTLSEnabled(true);
        emailSimples.setSmtpPort(587);
        emailSimples.setDebug(true);
        emailSimples.setAuthenticator(new DefaultAuthenticator("Seu email outlook", "sua senha"));
        emailSimples.setFrom("Seu email outlook");
        emailSimples.setSubject(formulario.getAssunto());
        emailSimples.setMsg(formulario.getTexto() + "     " + caminho2 + trabalho.getMatricula() + ".docx");
        emailSimples.addTo(trabalho.getEmail());
        emailSimples.send();
    } catch (EmailException ex) {
        //   System.out.println(""+ex);
        Logger.getLogger(FormularioDAO.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;

}

From source file:com.mycollab.servlet.EmailValidationServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String smtpUserName = request.getParameter("smtpUserName");
    String smtpPassword = request.getParameter("smtpPassword");
    String smtpHost = request.getParameter("smtpHost");
    String smtpPort = request.getParameter("smtpPort");
    String tls = request.getParameter("tls");
    String ssl = request.getParameter("ssl");

    int mailServerPort = 25;
    try {//from  w w w. j  a v a 2s  .c  o  m
        mailServerPort = Integer.parseInt(smtpPort);
    } catch (Exception e) {
        LOG.info("The smtp port value is not a number. We will use default port value is 25");
    }
    try {
        Email email = new SimpleEmail();
        email.setHostName(smtpHost);
        email.setSmtpPort(mailServerPort);
        email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword));
        if ("true".equals(tls)) {
            email.setStartTLSEnabled(true);
        } else {
            email.setStartTLSEnabled(false);
        }

        if ("true".equals(ssl)) {
            email.setSSLOnConnect(true);
        } else {
            email.setSSLOnConnect(false);
        }
        email.setFrom(smtpUserName);
        email.setSubject("MyCollab Test Email");
        email.setMsg("This is a test mail ... :-)");
        email.addTo(smtpUserName);
        email.send();
    } catch (EmailException e) {
        PrintWriter out = response.getWriter();
        out.write("Cannot establish SMTP connection. Please recheck your config.");
        LOG.warn("Can not login to SMTP", e);
    }
}