Example usage for org.apache.commons.mail SimpleEmail setSSL

List of usage examples for org.apache.commons.mail SimpleEmail setSSL

Introduction

In this page you can find the example usage for org.apache.commons.mail SimpleEmail setSSL.

Prototype

@Deprecated
public void setSSL(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:edu.du.penrose.systems.util.SendMail.java

/**
 * NOTE VERY WELL!! The sends an ssl email, when used with Fedora libraries this throws a SSL Exception, in order to fix this
 * The following SSL system properties are cleared and then restored after the email is sent. l...<br>
 * //ww w  .  ja v  a 2s  .  c  o m
 *    System.clearProperty( "javax.net.ssl.keyStore" );
 *  System.clearProperty( "javax.net.ssl.keyStorePassword" );
 *  System.clearProperty( "javax.net.ssl.keyStoreType" );
 *  System.clearProperty( "javax.net.ssl.trustStore" );
 *  System.clearProperty( "javax.net.ssl.trustStorePassword" );
 *  System.clearProperty( "javax.net.ssl.trustStoreType" );
 *  
 * @param recipients
 * @param subject
 * @param message
 * @param from
 * @param smptServerHost
 * @param smtpUser
 * @param smtpPassword
 * @param port
 * @param sslEmail
 */
public static void postMailWithAuthenication(String recipients[], String subject, String message, String from,
        String smptServerHost, String smtpUser, String smtpPassword, String port, boolean sslEmail) {
    if (from == null || !from.contains("@")) {
        logger.info("Unable to send email, missing from address.");
        return;
    }

    String user = smtpUser.trim();
    String password = smtpPassword.trim();

    int numberOfValidRecipients = 0;
    for (int i = 0; i < recipients.length; i++) {
        if (recipients[i] != null && recipients[i].length() > 0 && recipients[i].contains("@")) {
            numberOfValidRecipients++;
        }
    }

    if (numberOfValidRecipients == 0) {
        logger.info("Unable to send email, missing recipients address.");
        return;
    }

    SimpleEmail email = new SimpleEmail();
    email.setSSL(sslEmail);
    email.setSmtpPort(Integer.valueOf(port));
    email.setAuthentication(user, password);
    email.setHostName(smptServerHost);

    try {
        for (int i = 0; i < numberOfValidRecipients; i++) {
            email.addTo(recipients[i]);
        }
        email.setFrom(from);
        email.setSubject(subject);
        email.setMsg(message);

        //   System.setProperty( "javax.net.debug", "ssl" );

        String keyStore = System.getProperty("javax.net.ssl.keyStore");
        String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
        String keyStoreType = System.getProperty("javax.net.ssl.keyStoreType");
        String trustStore = System.getProperty("javax.net.ssl.trustStore");
        String trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");
        String trustStoreType = System.getProperty("javax.net.ssl.trustStoreType");

        System.clearProperty("javax.net.ssl.keyStore");
        System.clearProperty("javax.net.ssl.keyStorePassword");
        System.clearProperty("javax.net.ssl.keyStoreType");
        System.clearProperty("javax.net.ssl.trustStore");
        System.clearProperty("javax.net.ssl.trustStorePassword");
        System.clearProperty("javax.net.ssl.trustStoreType");

        email.send();

        System.setProperty("javax.net.ssl.keyStore", keyStore);
        System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
        System.setProperty("javax.net.ssl.keyStoreType", keyStoreType);
        System.setProperty("javax.net.ssl.trustStore", trustStore);
        System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
        System.setProperty("javax.net.ssl.trustStoreType", trustStoreType);

    } catch (Exception e) {
        logger.error("ERROR sending email:" + e.getLocalizedMessage());
    }

}

From source file:funcoes.funcoes.java

public static void enviardEmailSimpes(String emailPara, String nomePara, String assunto, String mensagem)
        throws EmailException {

    SimpleEmail email = new SimpleEmail();
    //Utilize o hostname do seu provedor de email
    //System.out.println("alterando hostname...");

    email.setHostName("smtp.gmail.com");
    //Quando a porta utilizada no  a padro (gmail = 465)
    email.setSmtpPort(465);//from w  w  w. j ava 2  s  .c  o  m
    //Adicione os destinatrios
    email.addTo(emailPara, nomePara);
    //Configure o seu email do qual enviar
    email.setFrom("cbjsolutions@gmail.com", "CBJ Solutions");
    //Adicione um assunto
    email.setSubject(assunto);
    //Adicione a mensagem do email
    email.setMsg(mensagem);
    //Para autenticar no servidor  necessrio chamar os dois mtodos abaixo
    //System.out.println("autenticando...");
    email.setSSL(true);
    email.setAuthentication("cbjsolutions", "slipclown");
    //System.out.println("enviando...");
    email.send();
    //System.out.println("Email enviado!");

}

From source file:br.com.painel.util.EnviarEmail.java

/**
 * /*w  w w  .j a va 2 s  .c  o m*/
 * @param destino coloque o e-mail que da pessoa que deseja enviar
 * @param nomeDestino o nome do destino
 * @param assunto o assunto do email
 * @param mensagem a mensagem do email
 * @throws EmailException 
 */
public void enviarEmail(String destino, String nomeDestino, String assunto, String mensagem)
        throws EmailException {

    SimpleEmail email = new SimpleEmail();
    email.setHostName("smtp.gmail.com"); // o servidor SMTP para envio do e-mail
    email.addTo(destino, nomeDestino); //destinatrio
    email.setFrom("rafaelvulner@gmail.com", "Recuperao de senha"); // remetente
    email.setSubject(assunto); // assunto do e-mail
    email.setMsg(mensagem); //conteudo do e-mail
    email.setAuthentication("rafaelvulner", "rafad18m01");
    email.setSmtpPort(465);
    email.setSSL(true);
    email.setTLS(true);
    email.send(); //envia o e-mail
}

From source file:br.com.hslife.catu.service.EmailService.java

/**
  * envia email simples (smente texto)/*  w w  w  .  j a v a2s  .co m*/
  * Nome remetente, e-mail remetente, nome destinatario, e-mail destinatario,
  * assunto, mensagem
  * @param nomeRemetente
  * @param nomeDestinatario
  * @param emailRemetente
  * @param emailDestinatario
  * @param assunto
  * @param mensagem
  * @throws EmailException
  */
public void enviaEmailSimples(String nomeRementente, String emailRemetente, String nomeDestinatario,
        String emailDestinatario, String assunto, StringBuilder mensagem) throws EmailException {

    SimpleEmail email = new SimpleEmail();
    email.setHostName("smtp.hslife.com.br"); // o servidor SMTP para envio do e-mail
    email.addTo(emailDestinatario, nomeDestinatario); //destinatrio
    email.setFrom(emailRemetente, nomeRementente); // remetente
    email.setSubject(assunto); // assunto do e-mail
    email.setMsg(mensagem.toString()); //conteudo do e-mail
    email.setAuthentication("nao-responde@hslife.com.br", "n0r3ply1@3");
    email.setCharset("UTF8");
    email.setSmtpPort(465);
    email.setSSL(true);
    email.setTLS(true);
    email.send();
}

From source file:dk.cubing.liveresults.action.admin.CompetitionAction.java

/**
 * @return//  ww  w.  j  a  v a  2s.c  om
 * @throws Exception
 */
public String save() throws Exception {
    Competition competition = getCompetition();
    if (competition.getCountry().length() != 2) {
        competition.setCountry(getCountryUtil().getCountryCodeByName(competition.getCountry()));
    } else if (getCountryUtil().getCountryByCode(competition.getCountry()) != null) {
        competition.setCountry(competition.getCountry().toUpperCase());
    }
    if ("".equals(competition.getWebsite())) {
        competition.setWebsite(null);
    }
    User user = new User(competition.getCompetitionId(),
            getPasswordEncoder().encodePassword(getPassword(), null), isEnabled(), true, true, true,
            new GrantedAuthority[] { new GrantedAuthorityImpl("ROLE_USER") });
    if (getUserDetailsManager().userExists(competition.getCompetitionId())) {
        log.info("Updating user: {}", competition.getCompetitionId());
        getUserDetailsManager().updateUser(user);
        getCompetitionService().update(competition);
    } else {
        log.info("Creating user: {}", competition.getCompetitionId());
        getUserDetailsManager().createUser(user);
        getCompetitionService().create(competition);
        // send mail to organiser.
        if (competition.getOrganiserEmail() != null && !competition.getOrganiserEmail().isEmpty()) {
            log.info("Sending login information to new user: {}", competition.getCompetitionId());
            try {
                SimpleEmail email = new SimpleEmail();
                email.setCharset(SimpleEmail.ISO_8859_1);
                email.setHostName(getText("email.smtp.server"));
                if (!getText("email.username").isEmpty() && !getText("email.password").isEmpty()) {
                    email.setAuthentication(getText("email.username"), getText("email.password"));
                }
                email.setSSL("true".equals(getText("email.ssl")));
                email.setSubject(getText("competitions.email.subject", new String[] { competition.getName() }));
                email.setMsg(getText("competitions.email.message",
                        new String[] { competition.getCompetitionId(), getPassword() }));
                email.setFrom(getText("competitions.email.senderEmail"), getText("competitions.email.sender"));
                email.addBcc(getText("competitions.email.senderEmail"), getText("competitions.email.sender"));
                email.addTo(competition.getOrganiserEmail(), competition.getOrganiser());
                email.send();
            } catch (Exception e) {
                log.error("Could not send email upon competition creation!", e);
            }
        }
    }
    return Action.SUCCESS;
}

From source file:dk.cubing.liveresults.action.admin.EmailAction.java

/**
 * @return/*from w  w w . ja  va  2  s  .  c  o m*/
 */
public String sendEmail() {
    if (getCompetition() != null) {
        try {
            SimpleEmail email = new SimpleEmail();
            email.setCharset(SimpleEmail.ISO_8859_1);
            email.setHostName(getText("email.smtp.server"));
            if (!getText("email.username").isEmpty() && !getText("email.password").isEmpty()) {
                email.setAuthentication(getText("email.username"), getText("email.password"));
            }
            email.setSSL("true".equals(getText("email.ssl")));
            email.setSubject(getSubject());
            email.setMsg(getBody());
            email.setFrom(getCompetition().getOrganiserEmail(), getCompetition().getOrganiser());
            email.addBcc(getCompetition().getWcaDelegateEmail(), getCompetition().getWcaDelegate());
            if (isSendToAccepted()) {
                for (String toAddress : getAcceptedCompetitors()) {
                    email.addBcc(toAddress);
                }
            }
            if (isSendToPending()) {
                for (String toAddress : getPendingCompetitors()) {
                    email.addBcc(toAddress);
                }
            }
            email.send();
            return Action.SUCCESS;
        } catch (Exception e) {
            log.error("Could not send email upon competition creation!", e);
            return Action.ERROR;
        }
    } else {
        log.error("Could not load competition!");
        return Action.ERROR;
    }
}

From source file:br.com.fabianoabreu.sendEmail.Email.java

public void sendEmail() throws EmailException {

    //alterar para o ip e a porta do seu proxy
    //System.setProperty("http.proxyHost", "10.100.122.181");
    //System.setProperty("http.proxyPort", "8080");
    ////a danada da autenticao que s funcionou desta forma...
    ////no seuUsuario e suaSenha voc coloca seu login e sua senha do proxy...
    //Authenticator.setDefault(new Authenticator() {
    //@Override//  w  w  w. ja v  a 2 s  .c  o m
    //protected PasswordAuthentication getPasswordAuthentication() {
    //return new PasswordAuthentication("1227149", "19751976".toCharArray());
    //}
    //});

    SimpleEmail email = new SimpleEmail();
    //Utilize o hostname do seu provedor de email
    System.out.println("alterando hostname...");
    email.setHostName("smtp.gmail.com");
    //Quando a porta utilizada no  a padro (gmail = 465)
    email.setSmtpPort(465);
    //Adicione os destinatrios
    email.addTo("solusoftic@gmail.com", "Renato");
    //Configure o seu email do qual enviar
    email.setFrom("solusoftic@gmail.com", "Renato");
    //Adicione um assunto
    email.setSubject("Test message");
    //Adicione a mensagem do email
    email.setMsg("This is a simple test of commons-email");
    //Para autenticar no servidor  necessrio chamar os dois mtodos abaixo
    System.out.println("autenticando...");
    email.setSSL(true);
    email.setAuthentication("solusoftic", "Bia19752002");
    System.out.println("enviando...");
    email.send();
    System.out.println("Email enviado!");
}

From source file:br.com.cgcop.administrativo.modelo.ContaEmail.java

public void enviarEmail(List<String> destinos, String mensagem, String titulo) throws EmailException {
    SimpleEmail email = new SimpleEmail();

    email.setHostName(this.host);
    //Quando a porta utilizada no  a padro (gmail = 465)
    email.setSmtpPort(this.porta);

    //Adicione os destinatrios
    for (String destino : destinos) {
        email.addTo(destino, "", "UTF-8");
    }/*w  ww.  ja  v a2s. co m*/
    email.setSentDate(new Date());

    //Configure o seu Email do qual enviar
    email.setFrom(this.email, this.empresa.getNome());
    //Adicione um assunto
    email.setSubject(titulo);
    //Adicione a mensagem do Email
    email.setMsg(Jsoup.parse(mensagem).text());
    //Para autenticar no servidor  necessrio chamar os dois mtodos abaixo
    email.setTLS(true);
    email.setSSL(true);

    email.setAuthentication(this.email, this.senha);
    email.send();
}

From source file:br.com.clinica.controller.MensagemController.java

public void sendEmail() {
    System.out.println("OOOOOOOOOOOOOOOOOOI");

    SimpleEmail email = new SimpleEmail();
    //Utilize o hostname do seu provedor de email
    System.out.println("alterando hostname...");
    email.setHostName("smtp.gmail.com");
    //Quando a porta utilizada no  a padro (gmail = 465)
    email.setSmtpPort(465);//from  w w  w.j  a v  a 2  s  .  com
    try {
        //Adicione os destinatrios
        email.addTo("luiz_paschoeto@hotmail.com", "Luiz_Henrique");
        email.setFrom("fhlluiz@gmail.com", "Luiz_Henrique");
        email.setMsg("This is a simple test of commons-email");
    } catch (EmailException ex) {
        Logger.getLogger(MensagemController.class.getName()).log(Level.SEVERE, null, ex);
    }
    //Configure o seu email do qual enviar

    //Adicione um assunto
    email.setSubject("Test message");
    //Adicione a mensagem do email

    //Para autenticar no servidor  necessrio chamar os dois mtodos abaixo
    System.out.println("autenticando...");
    email.setSSL(true);
    email.setAuthentication("fhlluiz@gmail.com", "864hzyw6");
    System.out.println("enviando...");

    try {
        email.send();
    } catch (EmailException ex) {
        Logger.getLogger(MensagemController.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println("Email enviado!");
}

From source file:org.jwebsocket.watchdog.notifier.MailNotifier.java

private void sendMail(String aMessage) throws Exception {
    //send a Simple e-mail receiving the message

    SimpleEmail lSm = new SimpleEmail();
    //Creating simple mail 

    lSm.setHostName(mHostName);/*  w w w  .  ja  v  a 2s .c o m*/
    //Hostname or ip address

    lSm.setSSL(false);
    //Use Certifacate SSL

    lSm.setSslSmtpPort(mPort);
    //Choosing the port

    for (int i = 0; i < mUsersList.size(); i++) {
        lSm.addTo(mUsersList.get(i));
        //Authentication
        //sm.setAuthentication("lzaila", "");
        //Whom you will send the e-mail
    }

    lSm.setFrom(mFrom);
    //the e-mail was send from

    lSm.setSubject(mSubject);
    //subject of message

    lSm.setMsg(aMessage);
    //and the body of the message
    //sm.setMsg("if you are receiving this message probably the 
    //server is presenting malfunctioning");

    lSm.send();
    //send the message
}