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

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

Introduction

In this page you can find the example usage for org.apache.commons.mail MultiPartEmail 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.github.somi92.seecsk.util.email.EmailSender.java

public static void sendEmail(EmailContainer ec) throws RuntimeException {

    try {/*w  w  w .j  av a 2s.  c  om*/

        String user = Config.vratiInstancu().vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_EMAIL);
        String password = Config.vratiInstancu()
                .vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_EMAIL_PASSWORD);

        EmailAttachment ea = new EmailAttachment();
        ea.setPath(ec.getAttachmentPath());
        ea.setDisposition(EmailAttachment.ATTACHMENT);
        ea.setDescription("Primer ispravno popunjene uplatnice za ?lanarinu");
        ea.setName("uplatnica.pdf");

        MultiPartEmail mpe = new MultiPartEmail();
        mpe.setDebug(true);
        mpe.setAuthenticator(new DefaultAuthenticator(user, password));
        mpe.setHostName(
                Config.vratiInstancu().vratiVrednost(Constants.EmailServerConfigKeys.EMAIL_SERVER_HOST));
        mpe.setSSLOnConnect(true);
        mpe.setStartTLSEnabled(true);
        mpe.setSslSmtpPort(
                Config.vratiInstancu().vratiVrednost(Constants.EmailServerConfigKeys.EMAIL_SERVER_PORT));
        mpe.setSubject(ec.getSubject());
        mpe.setFrom(ec.getFromEmail(),
                Config.vratiInstancu().vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_NAME));
        mpe.setMsg(ec.getMessage());

        mpe.addTo(ec.getToEmail());
        mpe.attach(ea);

        mpe.send();

    } catch (EmailException ex) {
        ex.printStackTrace();
        throw new RuntimeException("Sistem nije uspeo da poalje email. Pokuajte ponovo.");
    }
}

From source file:com.commander4j.email.JeMail.java

public void postMail(String recipientsTO[], String subject, String message, String attachmentFilename,
        String attachmentLongFilename) throws MessagingException {

    logger.debug("SMTP_AUTH_REQD=" + SMTP_AUTH_REQD);
    logger.debug("MAIL_SMTP_HOST_NAME=" + SMTP_HOST_NAME);
    logger.debug("MAIL_SMTP_AUTH_USER=" + SMTP_AUTH_USER);
    logger.debug("MAIL_SMTP_AUTH_PWD=********");
    logger.debug("MAIL_SMTP_PORT=" + MAIL_SMTP_PORT);
    logger.debug("MAIL_SMTP_SSL_PORT=" + MAIL_SMTP_SSL_PORT);
    logger.debug("MAIL_SMTP_FROM_ADRESS=" + SMTP_FROM_ADRESS);
    logger.debug("MAIL_SMTP_USE_SSL=" + SMTP_USE_SSL);

    //Email email = new SimpleEmail();
    logger.debug("Creating MultiPart Email");
    MultiPartEmail email = new MultiPartEmail();

    logger.debug("Setting Host Name to " + SMTP_HOST_NAME);
    email.setHostName(SMTP_HOST_NAME);/*w  ww .j  a v a 2  s . c o  m*/
    logger.debug("Setting SMTP Port to " + MAIL_SMTP_PORT);
    email.setSmtpPort(Integer.valueOf(MAIL_SMTP_PORT));

    logger.debug("Setting SMTP SSL Port to " + MAIL_SMTP_SSL_PORT);
    email.setSslSmtpPort(MAIL_SMTP_SSL_PORT);

    logger.debug("Setting Use SSL on Connect to  " + SMTP_USE_SSL);
    email.setSSLOnConnect(Boolean.valueOf(SMTP_USE_SSL));

    logger.debug("Authentication Required =  " + SMTP_AUTH_REQD);

    if (SMTP_AUTH_REQD.toUpperCase().equals("TRUE")) {
        email.setAuthenticator(new DefaultAuthenticator(SMTP_AUTH_USER, SMTP_AUTH_PWD));

    }

    logger.debug("Setting SMTP USE SSL =  " + SMTP_USE_SSL);
    email.setSSLOnConnect(Boolean.valueOf(SMTP_USE_SSL));

    logger.debug("Setting SMTP USE TLS =  " + SMTP_USE_TLS);
    email.setStartTLSEnabled(Boolean.valueOf(SMTP_USE_TLS));
    email.setStartTLSRequired(Boolean.valueOf(SMTP_USE_TLS));

    try {
        logger.debug("From Address =  " + SMTP_FROM_ADRESS);
        email.setFrom(SMTP_FROM_ADRESS);
        email.setSubject(subject);
        email.setMsg(message + "\n\n");
        for (int x = 1; x <= recipientsTO.length; x++) {
            logger.debug("Add To Address =  " + recipientsTO[x - 1]);
            email.addTo(recipientsTO[x - 1]);
        }

        if (JUtility.replaceNullStringwithBlank(attachmentFilename).equals("") == false) {
            // Create the attachment
            EmailAttachment attachment = new EmailAttachment();
            attachment.setPath(attachmentLongFilename);
            attachment.setDisposition(EmailAttachment.ATTACHMENT);
            attachment.setDescription(attachmentFilename);
            attachment.setName(attachmentFilename);

            // add the attachment
            logger.debug("Add Attachment");
            email.attach(attachment);
        }

        logger.debug("Sending");
        email.send();
        logger.debug("Sent successfully");
    } catch (EmailException e) {
        logger.error("Unable to send email : " + e.getCause().getMessage());
    }

}

From source file:net.big_oh.postoffice.PostOfficeService.java

public void sendMail(Set<String> toRecipients, String subject, String messageText, Set<File> attachments)
        throws EmailException {

    Duration dur = new Duration(this.getClass());
    logger.info("Begin send email to " + toRecipients.size() + " recipient(s) with " + attachments.size()
            + " attachment(s).");

    // validate the method parameters
    if (toRecipients.isEmpty()) {
        throw new IllegalArgumentException("Cowardly refusing to send an email message with no recipients.");
    }/*from w  ww  . j av a  2  s  .  c om*/

    // instantiate an email object
    MultiPartEmail email = new MultiPartEmail();

    // establish SMTP end-point details
    email.setHostName(smtpServerHost);
    email.setSSL(transportWithSsl);
    if (transportWithSsl) {
        email.setSslSmtpPort(Integer.toString(smtpServerPort));
    } else {
        email.setSmtpPort(smtpServerPort);
    }

    // establish SMTP authentication details
    if (!StringUtils.isBlank(smtpUserName) && !StringUtils.isBlank(smtpPassword)) {
        email.setAuthentication(smtpUserName, smtpPassword);
    }
    email.setTLS(authenticateWithTls);

    // establish basic email delivery details
    email.setDebug(debug);
    email.setFrom(sendersFromAddress);
    for (String toRecipient : toRecipients) {
        email.addTo(toRecipient);
    }

    // set email content
    email.setSubject(subject);
    email.setMsg(messageText);

    // create attachments to the email
    for (File file : attachments) {

        if (!file.exists()) {
            logger.error("Skipping attachment file that does not exist: " + file.toString());
            continue;
        }

        if (!file.isFile()) {
            logger.error("Skipping attachment file that is not a normal file: " + file.toString());
            continue;
        }

        EmailAttachment attachment = new EmailAttachment();
        attachment.setPath(file.getPath());
        attachment.setDisposition(EmailAttachment.ATTACHMENT);
        attachment.setName(file.getName());

        email.attach(attachment);

    }

    // Send message
    email.send();

    dur.stop("Finished sending email to " + toRecipients.size() + " recipient(s)");

}

From source file:com.t2tierp.controller.nfe.NfeCabecalhoController.java

public void enviaEmail() {
    try {//from w w w.ja  v  a2s.co  m
        if (getObjeto().getStatusNota().intValue() != 5) {
            throw new Exception("NF-e no autorizada. Envio de email no permitido!");
        }

        NfeConfiguracao configuracao = nfeConfiguracaoDao.getBean(NfeConfiguracao.class,
                new ArrayList<Filtro>());

        if (configuracao == null) {
            throw new Exception("Configurao NFe no definida");
        }
        if (configuracao.getEmailAssunto() == null || configuracao.getEmailSenha() == null
                || configuracao.getEmailServidorSmtp() == null || configuracao.getEmailTexto() == null
                || configuracao.getEmailUsuario() == null) {
            throw new Exception("Configurao de envio de email no definida");
        }

        MultiPartEmail email = new MultiPartEmail();
        email.setHostName(configuracao.getEmailServidorSmtp());
        email.setFrom(configuracao.getEmpresa().getEmail());
        email.addTo(getObjeto().getDestinatario().getEmail());
        email.setSubject(configuracao.getEmailAssunto());
        email.setMsg(configuracao.getEmailTexto());

        email.setAuthentication(configuracao.getEmailUsuario(), configuracao.getEmailSenha());
        if (configuracao.getEmailPorta() != null) {
            if (configuracao.getEmailAutenticaSsl() != null
                    && configuracao.getEmailAutenticaSsl().equals("S")) {
                email.setSSLOnConnect(true);
                email.setSslSmtpPort(configuracao.getEmailPorta().toString());
            } else {
                email.setSmtpPort(configuracao.getEmailPorta());
            }
        }

        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();

        EmailAttachment anexo = new EmailAttachment();
        anexo.setPath(context.getRealPath(diretorioXml) + System.getProperty("file.separator")
                + getObjeto().getChaveAcesso() + getObjeto().getDigitoChaveAcesso() + "-nfeproc.xml");
        anexo.setDisposition(EmailAttachment.ATTACHMENT);
        anexo.setDescription("Nota Fiscal Eletronica");
        anexo.setName(getObjeto().getChaveAcesso() + getObjeto().getDigitoChaveAcesso() + "-nfeproc.xml");

        EmailAttachment anexo2 = new EmailAttachment();
        anexo2.setPath(context.getRealPath(diretorioXml) + System.getProperty("file.separator")
                + getObjeto().getChaveAcesso() + getObjeto().getDigitoChaveAcesso() + ".pdf");
        anexo2.setDisposition(EmailAttachment.ATTACHMENT);
        anexo2.setDescription("Nota Fiscal Eletronica");
        anexo2.setName(getObjeto().getChaveAcesso() + getObjeto().getDigitoChaveAcesso() + ".pdf");

        email.attach(anexo);
        email.attach(anexo2);

        email.send();

        FacesContextUtil.adiconaMensagem(FacesMessage.SEVERITY_INFO, "Email enviado com sucesso", "");
    } catch (Exception ex) {
        ex.printStackTrace();
        FacesContextUtil.adiconaMensagem(FacesMessage.SEVERITY_ERROR, "Ocorreu um erro ao enviar o email.",
                ex.getMessage());
    }
}

From source file:org.kantega.respiro.mail.ServerConfig.java

public MultiPartEmail newMail() {
    MultiPartEmail mail = new MultiPartEmail();

    mail.setHostName(host);/*from   w  w w  .j  av a2s .  co m*/
    if (!ssl)
        mail.setSmtpPort(port);
    else
        mail.setSslSmtpPort(valueOf(port));
    if (username != null && password != null)
        mail.setAuthentication(username, password);

    try {
        if (!to.isEmpty())
            mail.setTo(to);
        if (!cc.isEmpty())
            mail.setCc(cc);
        if (!bcc.isEmpty())
            mail.setBcc(bcc);
        if (fromMail != null)
            mail.setFrom(fromMail);
    } catch (EmailException e) {
        throw new RuntimeException(e);
    }

    return mail;
}

From source file:org.sakaiproject.nakamura.email.outgoing.LiteOutgoingEmailMessageListener.java

/**
 * Set transfer options on the email based on configuration of this service.
 *
 * @param email The email where to set options.
 *//*from   w w w.  ja  v a  2 s . c  om*/
private void setOptions(MultiPartEmail email) {
    email.setHostName(smtpServer);
    email.setTLS(useTls);
    email.setSSL(useSsl);
    if (useSsl) {
        email.setSslSmtpPort(Integer.toString(smtpPort));
    } else {
        email.setSmtpPort(smtpPort);
    }

    if (!StringUtils.isBlank(authUser) && !StringUtils.isBlank(authPass)) {
        email.setAuthentication(authUser, authPass);
    }
}