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

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

Introduction

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

Prototype

public void setSslSmtpPort(final String sslSmtpPort) 

Source Link

Document

Sets the SSL port to use for the SMTP transport.

Usage

From source file:com.tcc.servidor_tcc.api.SystematicReviewResource.java

private void sendEmailNotification(Reviewer reviewer, boolean registered, SystematicReview sr) {
    SimpleEmail email = new SimpleEmail();
    email.setSSLOnConnect(true);//from   w w w  . j a va 2s  .  c  o  m
    email.setHostName("smtp.gmail.com");
    email.setSslSmtpPort("465");
    email.setAuthenticator(new DefaultAuthenticator("mobrevsys@gmail.com", "revisaosistematica"));
    try {
        email.setFrom("mobrevsys@gmail.com");

        email.setDebug(true);

        email.setSubject("MobRevSys - Invited to participate in a Systematic Review");
        if (registered) {
            email.setMsg("Hello " + reviewer.getName() + ",\n" + sr.getOwner().getName()
                    + " has invited you to participate in a " + "Systematic Review with the title of \""
                    + sr.getTitle() + "\".\n" + "Best Regards,\n MobRevSys");
        } else {
            email.setMsg("Hello " + reviewer.getEmail() + ",\n" + sr.getOwner().getName()
                    + "has invited you to participate in a " + "Systematic Review with the title of \""
                    + sr.getTitle() + "\".\n"
                    + "Please download the MobRevSys app and register to contribute.\n"
                    + "Best Regards,\n MobRevSys");
        }
        email.addTo(reviewer.getEmail());

        email.send();

    } catch (EmailException e) {
        e.printStackTrace();
    }
}

From source file:br.com.hslife.orcamento.component.EmailComponent.java

public void enviarEmail() throws ApplicationException, EmailException, SendGridException {
    // Carrega as configuraes de envio de e-mail
    this.populateParameters();

    if (metodoEnvio.equals("SENDGRID")) {
        this.enviarEmailSendGrid();
        return;/*from  w  w  w .j  a  va2 s  .c  o m*/
    }

    // Instancia o objeto de e-mail
    SimpleEmail email = new SimpleEmail();

    // Atribui ao objeto os parmetros passados ao mtodo
    email.addTo(emailDestinatario, destinatario, charset);
    email.setFrom(emailRemetente, remetente, charset); // remetente
    email.setSubject(assunto);
    email.setMsg(mensagem);

    // Atribui os demais parmetros vindos de opes do sistema
    email.setHostName(servidor);
    email.setSmtpPort(porta);
    email.setAuthentication(usuario, senha);
    if (usarSSL) {
        email.setSSLOnConnect(true);
        email.setSslSmtpPort(String.valueOf(porta));
    } else {
        email.setSSLOnConnect(false);
    }
    email.setCharset(charset);
    email.setSSLCheckServerIdentity(false);
    email.send();
}

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);//from  w  ww.j  a  v  a  2 s .  c  om
    //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
}

From source file:org.sonar.plugins.emailnotifications.EmailNotificationChannel.java

private void send(EmailMessage emailMessage) throws EmailException {
    // Trick to correctly initilize javax.mail library
    ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

    try {//w  ww.  j a va 2s  .  c  o m
        LOG.debug("Sending email: {}", emailMessage);
        String host = null;
        try {
            host = new URL(configuration.getServerBaseURL()).getHost();
        } catch (MalformedURLException e) {
            // ignore
        }

        SimpleEmail email = new SimpleEmail();
        if (StringUtils.isNotBlank(host)) {
            /*
            * Set headers for proper threading: GMail will not group messages, even if they have same subject, but don't have "In-Reply-To" and
            * "References" headers. TODO investigate threading in other clients like KMail, Thunderbird, Outlook
            */
            if (StringUtils.isNotEmpty(emailMessage.getMessageId())) {
                String messageId = "<" + emailMessage.getMessageId() + "@" + host + ">";
                email.addHeader(IN_REPLY_TO_HEADER, messageId);
                email.addHeader(REFERENCES_HEADER, messageId);
            }
            // Set headers for proper filtering
            email.addHeader(LIST_ID_HEADER, "Sonar <sonar." + host + ">");
            email.addHeader(LIST_ARCHIVE_HEADER, configuration.getServerBaseURL());
        }
        // Set general information
        email.setCharset("UTF-8");
        String from = StringUtils.isBlank(emailMessage.getFrom()) ? FROM_NAME_DEFAULT
                : emailMessage.getFrom() + " (Sonar)";
        email.setFrom(configuration.getFrom(), from);
        email.addTo(emailMessage.getTo(), " ");
        String subject = StringUtils.defaultIfBlank(StringUtils.trimToEmpty(configuration.getPrefix()) + " ",
                "") + StringUtils.defaultString(emailMessage.getSubject(), SUBJECT_DEFAULT);
        email.setSubject(subject);
        email.setMsg(emailMessage.getMessage());
        // Send
        email.setHostName(configuration.getSmtpHost());
        if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "SSL")) {
            email.setSSL(true);
            email.setSslSmtpPort(String.valueOf(configuration.getSmtpPort()));

            // this port is not used except in EmailException message, that's why it's set with the same value than SSL port.
            // It prevents from getting bad message.
            email.setSmtpPort(configuration.getSmtpPort());
        } else if (StringUtils.isBlank(configuration.getSecureConnection())) {
            email.setSmtpPort(configuration.getSmtpPort());
        } else {
            throw new SonarException(
                    "Unknown type of SMTP secure connection: " + configuration.getSecureConnection());
        }
        if (StringUtils.isNotBlank(configuration.getSmtpUsername())
                || StringUtils.isNotBlank(configuration.getSmtpPassword())) {
            email.setAuthentication(configuration.getSmtpUsername(), configuration.getSmtpPassword());
        }
        email.setSocketConnectionTimeout(SOCKET_TIMEOUT);
        email.setSocketTimeout(SOCKET_TIMEOUT);
        email.send();

    } finally {
        Thread.currentThread().setContextClassLoader(classloader);
    }
}

From source file:org.sonar.server.notification.email.EmailNotificationChannel.java

private void configureSecureConnection(SimpleEmail email) {
    if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "ssl")) {
        email.setSSLOnConnect(true);/*from   w  w w  .  j a v a 2  s. co  m*/
        email.setSslSmtpPort(String.valueOf(configuration.getSmtpPort()));

        // this port is not used except in EmailException message, that's why it's set with the same value than SSL port.
        // It prevents from getting bad message.
        email.setSmtpPort(configuration.getSmtpPort());
    } else if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "starttls")) {
        email.setStartTLSEnabled(true);
        email.setStartTLSRequired(true);
        email.setSmtpPort(configuration.getSmtpPort());
    } else if (StringUtils.isBlank(configuration.getSecureConnection())) {
        email.setSmtpPort(configuration.getSmtpPort());
    } else {
        throw new SonarException(
                "Unknown type of SMTP secure connection: " + configuration.getSecureConnection());
    }
}

From source file:pl.bcichecki.rms.config.EmailConfiguration.java

public SimpleEmail getConfiguredEmail() throws EmailException {
    SimpleEmail email = new SimpleEmail();

    email.setFrom(fromAddress, from);/*from  w  ww  .j a va2s.com*/
    email.setHostName(host);
    email.setSmtpPort(port);

    if (ssl) {
        email.setSSL(ssl);
        email.setSslSmtpPort(String.valueOf(port));
    }

    if (authenticate) {
        email.setAuthentication(fromAddress, password);
    }

    return email;
}