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

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

Introduction

In this page you can find the example usage for org.apache.commons.mail MultiPartEmail setTLS.

Prototype

@Deprecated
public void setTLS(final boolean withTLS) 

Source Link

Document

Set or disable the STARTTLS encryption.

Usage

From source file:com.zuora.api.UsageAdjInvoiceRegenerator.java

public static void main(String[] args) {

    String exportIdPRPC, exportIdII, exportFileIdII, exportFileIdPRPC, queryII, queryPRPC;

    boolean hasArgs = false;
    if (args != null && args.length >= 1) {
        UsageAdjInvoiceRegenerator.PROPERTY_FILE_NAME = args[0];
        hasArgs = true;//from w  w  w  .jav  a 2  s.  com
    }
    AppParamManager.initParameters(hasArgs);
    if (!AppParamManager.TASK_ID.equals("")) {
        try {
            zApiClient = new ApiClient(AppParamManager.API_URL, AppParamManager.USER_NAME,
                    AppParamManager.USER_PASSWORD, AppParamManager.USER_SESSION);

            zApiClient.login();
        } catch (Exception ex) {
            Logger.print(ex);
            Logger.print("RefreshSession - There's exception in the API call.");
        }

        queryPRPC = AppParamManager.PRPCexportQuery;
        queryII = AppParamManager.IIexportQuery;

        exportIdPRPC = zApiClient.createExport(queryPRPC);

        exportIdII = zApiClient.createExport(queryII);

        // ERROR createExport fails
        if (exportIdII == null || exportIdII.equals("")) {
            Logger.print("Error. Failed to create Invoice Item Export");
            //return false;
        }

        // ERROR createExport fails
        if (exportIdPRPC == null || exportIdPRPC.equals("")) {
            Logger.print("Error. Failed to create PRPC export");
            //return false;
        }

        exportFileIdII = zApiClient.getExportFileId(exportIdII);

        if (exportFileIdII == null) {
            Logger.print("Error. Failed to get Invoice Item Export file Id");
            //log.closeLogFile();
            //return false;
        }

        exportFileIdPRPC = zApiClient.getExportFileId(exportIdPRPC);

        if (exportFileIdPRPC == null) {
            Logger.print("Error. Failed to get PRPC Export file Id");
            //log.closeLogFile();
            //return false;
        }
        // get the export file from zuora
        //zApiClient.getFile(exportFileIdII, exportFileIdTI);

        /*
        Logger.print("II export ID: "+exportFileIdII);
        Logger.print("TI export ID: "+exportFileIdTI);
        */

        Logger.print("Opening Export file");

        //Base64 bs64 = new BASE64Encoder();
        /*
        String login = AppParamManager.USER_NAME+":"+AppParamManager.USER_PASSWORD;
        String authorization ="Basic "+ Base64.encodeBase64String(login.getBytes());
        String zendpoint = "";
        */

        String authorization = "";
        //Base64 bs64 = new BASE64Encoder();
        if (AppParamManager.USER_SESSION.isEmpty()) {
            String login = AppParamManager.USER_NAME + ":" + AppParamManager.USER_PASSWORD;
            authorization = "Basic " + Base64.encodeBase64String(login.getBytes());
        } else {
            authorization = "ZSession " + AppParamManager.USER_SESSION;
        }
        String zendpoint = "";

        try {

            /*
            if( AppParamManager.API_URL.contains("api") ){
               //look in api sandbox
               zendpoint = "https://apisandbox.zuora.com/apps/api/file/";
            } else {
               //look in production
               zendpoint = "https://www.zuora.com/apps/api/file/";
            }
            */

            int index = AppParamManager.API_URL.indexOf("apps");
            index = index + 5;
            zendpoint = AppParamManager.API_URL.substring(0, index) + "api/file/";
            Logger.print(zendpoint);

            //zendpoint = AppParamManager.FILE_URL;

            //Start reading Invoice Items

            String zendpointII = zendpoint + exportFileIdII + "/";

            URL url = new URL(zendpointII);
            URLConnection uc = url.openConnection();
            //Logger.print("Opening invoice item file: "+exportFileIdII+" authorization: "+authorization);
            uc.setRequestProperty("Authorization", authorization);

            InputStream content = (InputStream) uc.getInputStream();
            BufferedReader in = new BufferedReader(new InputStreamReader(content));
            CSVReader cvsReader = new CSVReader(in);

            List<String[]> batchOfRawDataList = null;

            while ((batchOfRawDataList = cvsReader.parseEntity()) != null) {
                UsageAdjInvoiceRegenerator.readInvoices(batchOfRawDataList, cvsReader.getBatchStartLineNumber(),
                        "InvoiceItem");
            }

            in.close();

            String zenpointPRPC = zendpoint + exportFileIdPRPC + "/";
            url = new URL(zenpointPRPC);
            uc = url.openConnection();
            uc.setRequestProperty("Authorization", authorization);
            content = (InputStream) uc.getInputStream();
            in = new BufferedReader(new InputStreamReader(content));
            cvsReader = new CSVReader(in);

            while ((batchOfRawDataList = cvsReader.parseEntity()) != null) {
                UsageAdjInvoiceRegenerator.readInvoices(batchOfRawDataList, cvsReader.getBatchStartLineNumber(),
                        "PRPCItem");
            }

            in.close();
            Logger.print("start processing values");

            UsageAdjInvoiceRegenerator chargeAdjustment = new UsageAdjInvoiceRegenerator();
            int[] results;
            int totalErrors = 0;
            String emailmsg = "";
            Logger.print("----------------------------------------");
            Logger.print("start creating usages");
            results = zApiClient.createUsageItems(newUsageCollection);
            if (results[1] != 0) {
                emailmsg = (results[0] - results[1]) + "/" + results[0] + " usage creation ";
            }
            totalErrors = totalErrors + results[1];

            Logger.print("start cancelling invoices");
            results = zApiClient.alterInvoices(newUsageCollection, "cancel");
            if (results[1] != 0) {
                emailmsg = (results[0] - results[1]) + "/" + results[0] + " invoice cancellation ";
            }
            totalErrors = totalErrors + results[1];

            Logger.print("start deleting usages");
            results = zApiClient.deleteUsageItems(deleteList);
            if (results[1] != 0) {
                emailmsg = (results[0] - results[1]) + "/" + results[0] + " usage deletion ";
            }
            totalErrors = totalErrors + results[1];

            Logger.print("start regenerating invoices");
            results = zApiClient.alterInvoices(newUsageCollection, "generate");
            if (results[1] != 0) {
                emailmsg = (results[0] - results[1]) + "/" + results[0] + " invoice generation ";
            }
            totalErrors = totalErrors + results[1];

            Logger.print("start deleting old invoices");
            results = zApiClient.alterInvoices(newUsageCollection, "delete");
            if (results[1] != 0) {
                emailmsg = (results[0] - results[1]) + "/" + results[0] + " invoice deletion ";
            }
            totalErrors = totalErrors + results[1];

            // Create the attachment
            EmailAttachment attachment = new EmailAttachment();
            if (totalErrors > 0) {

                String logFileName = AppParamManager.OUTPUT_FOLDER_LOCATION + File.separator + "runtime_log_"
                        + AppParamManager.OUTPUT_FILE_POSTFIX + ".txt";

                attachment.setPath(logFileName);
                attachment.setDisposition(EmailAttachment.ATTACHMENT);
                attachment.setDescription("System Log");
                attachment.setName("System Log");
            }

            MultiPartEmail email = new MultiPartEmail();
            email.setSmtpPort(587);
            email.setAuthenticator(
                    new DefaultAuthenticator(AppParamManager.EMAIL_ADDRESS, AppParamManager.EMAIL_PASSWORD));
            email.setDebug(false);
            email.setHostName("smtp.gmail.com");
            email.setFrom("zuora@gmail.com");

            if (totalErrors > 0) {
                email.setSubject("Base Calc Processor Finished with Errors");
                email.setMsg("The base calc processing has finished " + emailmsg + "records successfully.");
            } else {
                email.setSubject("Base Calc Processor Finished Successfully");
                emailmsg = (results[0] - results[1]) + "/" + results[0] + " invoice ";
                email.setMsg("The base calc processing has finished " + emailmsg + "records successfully.");
            }
            email.setTLS(true);
            email.addTo(AppParamManager.RECIPIENT_ADDRESS);
            if (totalErrors > 0) {
                email.attach(attachment);
            }
            email.send();
            System.out.println("Mail sent!");
            if (hasArgs) {
                Connection conn = AppParamManager.getConnection();
                Statement stmt = conn.createStatement();
                DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                java.util.Date date = new Date();
                stmt.executeUpdate("UPDATE TASK SET STATUS = 'completed', END_TIME = '"
                        + dateFormat.format(date) + "' WHERE ID = " + AppParamManager.TASK_ID);
                Utility.saveLogToDB(conn);
                conn.close();
            }

        } catch (Exception e) {
            Logger.print("Failure, gettingFile.");
            Logger.print("Error getting the export file: " + e.getMessage());
            //System.out.println("Error getting the export file: "+e.getMessage());
            try {
                Connection conn = AppParamManager.getConnection();
                Statement stmt = conn.createStatement();
                DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                java.util.Date date = new Date();
                stmt.executeUpdate("UPDATE TASK SET STATUS = 'failed', END_TIME = '" + dateFormat.format(date)
                        + "' WHERE ID = " + AppParamManager.TASK_ID);
                Utility.saveLogToDB(conn);
                conn.close();
            } catch (Exception e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            }
        }
    } else {
        Logger.print("No tasks in wait status");
    }
}

From source file:emailworkshop.EmailWorkshop.java

public static void enviaEmailComAnexo(String mailFrom, String senhaFrom, String emailTo, String nomeTo)
        throws EmailException {
    // cria o anexo 1.
    EmailAttachment anexo1 = new EmailAttachment();
    anexo1.setPath("Certificado.pdf"); //caminho do arquivo (RAIZ_PROJETO/teste/teste.txt)
    anexo1.setDisposition(EmailAttachment.ATTACHMENT);
    anexo1.setDescription("anexo");
    anexo1.setName("Certificado.pdf");

    // configura o email
    MultiPartEmail email = new MultiPartEmail();
    email.setHostName("smtp.gmail.com"); // o servidor SMTP para envio do e-mail
    email.addTo(emailTo, nomeTo); //destinatrio
    email.setFrom(mailFrom, "UFPR"); // remetente
    email.setSubject("Certificado II Workshop de Inovao"); // assunto do e-mail
    email.setMsg("Segue anexo o Certificado de participaao no II Workshop, Obrigado pela presena! \n "
            + emailTo); //conteudo do e-mail
    email.setAuthentication(mailFrom, senhaFrom);
    email.setSmtpPort(465);//www. ja va2  s. c o  m
    email.setSSL(true);
    email.setTLS(true);
    // adiciona arquivo(s) anexo(s)
    email.attach(anexo1);
    // envia o email
    email.send();
}

From source file:com.cs.sis.controller.EmailController.java

private MultiPartEmail criarEmail(String destinatario, String assunto, String msg) throws EmailException {
    MultiPartEmail email = new MultiPartEmail();
    email.setHostName(HOST_NAME); // o servidor SMTP para envio do e-mail
    email.addTo(destinatario); //destinatrio
    email.setFrom(EMAIL_REMETENTE); // remetente
    email.setSubject(assunto); // assunto do e-mail
    email.setMsg(msg); //conteudo do e-mail
    email.setAuthentication(EMAIL_REMETENTE, new StringBuffer(EMAIL_SENHA).reverse().toString());
    email.setSmtpPort(465);/*from www .j  av a 2s . co  m*/
    email.setSSL(true);
    email.setTLS(true);
    return email;
}

From source file:com.client.named.RegisterPrestario.java

public void sendEmail(String senderId, String subject, String body)
        throws UnsupportedEncodingException, MessagingException {

    String myEmailId = "computo.citecvlp@gmail.com";
    String myPassword = "impresora73";

    try {//from  www  . ja  v  a  2  s . c  om
        MultiPartEmail email = new MultiPartEmail();
        email.setSmtpPort(587);
        email.setAuthenticator(new DefaultAuthenticator(myEmailId, myPassword));
        email.setDebug(true);
        email.setHostName("smtp.gmail.com");
        email.setFrom(myEmailId);
        email.setSubject("activacion cuenta laboratorio computo UABC");
        email.setMsg(body);
        email.addTo(senderId);
        email.setTLS(true);

        /* EmailAttachment attachment = new EmailAttachment();
         attachment.setPath("/Users/fahadparkar/Desktop/Fahim/tables.xlsx");
         attachment.setDisposition(EmailAttachment.ATTACHMENT);
         attachment.setDescription("Excel");
         attachment.setName("tables.xlsx");
         email.attach(attachment);*/
        email.send();
        System.out.println("Mail sent!");
    } catch (EmailException e) {
        System.out.println("Exception :: " + e);
    }

}

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.");
    }//w  w w. j  a  v  a 2s.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.googlecode.fascinator.portal.process.EmailNotifier.java

public boolean emailAttachment(String from, String recipient, String subject, String body, byte[] attachData,
        String attachDataType, String attachFileName, String attachDesc) throws Exception {
    MultiPartEmail email = new MultiPartEmail();
    email.attach(new ByteArrayDataSource(attachData, attachDataType), attachFileName, attachDesc,
            EmailAttachment.ATTACHMENT);
    log.debug("Email host: " + host);
    log.debug("Email port: " + port);
    log.debug("Email username: " + username);
    log.debug("Email from: " + from);
    log.debug("Email to: " + recipient);
    log.debug("Email Subject is: " + subject);
    log.debug("Email Body is: " + body);
    email.setHostName(host);//from   w  w w  .j  a va  2 s.  c o  m
    email.setSmtpPort(Integer.parseInt(port));
    email.setAuthenticator(new DefaultAuthenticator(username, password));
    // the method setSSL is deprecated on the newer versions of commons
    // email...
    email.setSSL("true".equalsIgnoreCase(ssl));
    email.setTLS("true".equalsIgnoreCase(tls));
    email.setFrom(from);
    email.setSubject(subject);
    email.setMsg(body);
    if (recipient.indexOf(",") >= 0) {
        String[] recs = recipient.split(",");
        for (String rec : recs) {
            email.addTo(rec);
        }
    } else {
        email.addTo(recipient);
    }
    email.send();
    return true;
}

From source file:au.edu.ausstage.utils.EmailManager.java

/**
 * A method for sending a simple email message
 *
 * @param subject the subject of the message
 * @param message the text of the message
 * @param attachmentPath the path to the attachment
 *
 * @return true, if and only if, the email is successfully sent
 *//*  www  .  ja va  2s. com*/
public boolean sendMessageWithAttachment(String subject, String message, String attachmentPath) {

    // check the input parameters
    if (InputUtils.isValid(subject) == false || InputUtils.isValid(message) == false
            || InputUtils.isValid(attachmentPath) == false) {
        throw new IllegalArgumentException("All parameters are required");
    }

    try {
        // define helper variables
        MultiPartEmail email = new MultiPartEmail();

        // configure the instance of the email class
        email.setSmtpPort(options.getPortAsInt());

        // define authentication if required
        if (InputUtils.isValid(options.getUser()) == true) {
            email.setAuthenticator(new DefaultAuthenticator(options.getUser(), options.getPassword()));
        }

        // turn on / off debugging
        email.setDebug(DEBUG);

        // set the host name
        email.setHostName(options.getHost());

        // set the from email address
        email.setFrom(options.getFromAddress());

        // set the subject
        email.setSubject(subject);

        // set the message
        email.setMsg(message);

        // set the to address
        String[] addresses = options.getToAddress().split(":");

        for (int i = 0; i < addresses.length; i++) {
            email.addTo(addresses[i]);
        }

        // set the security options
        if (options.getTLS() == true) {
            email.setTLS(true);
        }

        if (options.getSSL() == true) {
            email.setSSL(true);
        }

        // build the attachment
        EmailAttachment attachment = new EmailAttachment();
        attachment.setPath(attachmentPath);
        attachment.setDisposition(EmailAttachment.ATTACHMENT);
        attachment.setDescription("Sanitised Twitter Message");
        attachment.setName("twitter-message.txt");

        // add the attachment
        email.attach(attachment);

        // send the email
        email.send();

    } catch (EmailException ex) {
        if (DEBUG) {
            System.err.println("ERROR: Sending of email failed.\n" + ex.toString());
        }

        return false;
    }
    return true;
}

From source file:Controle.EmailControl.java

public boolean enviarEmail(ModelEmail e) throws EmailException {
    try {//from  w ww  . j  a  va2  s  .co  m
        MultiPartEmail email = new MultiPartEmail(); //Classe responsvel por enviar o email
        String emailRemetente = e.getRemetente(); //gmail: testepooemail@gmail.com | hotmail: programacao451@hotmail.com
        String nomeRemetente = e.getNomeRemetente();
        String senhaRemetente = e.getSenha(); //gmail: ifmginfo | hotmail: ifmginfo12
        String hostName = ""; //gmail: smtp.gmail.com | hotmail: smtp-mail.outlook.com
        if (e.isTipoEmail()) {
            hostName = "smtp-mail.outlook.com";
        } else {
            hostName = "smtp.gmail.com";
        }
        String emailDestinatario = e.getDestinatario(); //email do destinatrio
        int porta = 587;
        String portaSmtp = Integer.toString(porta); //converte a porta para String

        email.setSmtpPort(porta); //porta para envio
        email.setAuthenticator(new DefaultAuthenticator(emailRemetente, senhaRemetente)); //autenticao da conta
        email.setDebug(true);
        email.setHostName(hostName); //varia de cada servidor
        //propriedades para o envio  do email
        email.getMailSession().getProperties().put("mail.smtps.auth", true);
        email.getMailSession().getProperties().put("mail.debug", "true");
        email.getMailSession().getProperties().put("mail.smtps.port", portaSmtp);
        email.getMailSession().getProperties().put("mail.smtps.socketFactory.port", portaSmtp);
        email.getMailSession().getProperties().put("mail.smtps.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        email.getMailSession().getProperties().put("mail.smtps.socketFactory.fallback", "false");
        email.getMailSession().getProperties().put("mail.smtp.starttls.enable", true);
        email.getMailSession().getProperties().put("mail.smtp.starttls.required", true);
        email.getMailSession().getProperties().put("mail.smtp.ssl.trust", hostName);
        email.setFrom(emailRemetente, nomeRemetente); //email e nome de quem est enviando o email
        email.setSubject(e.getAssunto()); //Assunto do email
        email.setMsg(e.getMensagem()); //Mensagem do email
        email.addTo(emailDestinatario); //destinatrio do email
        email.setTLS(true); //define o mtodo de criptografia
        if (e.isPossuiAnexo()) {
            EmailAttachment anexo1 = new EmailAttachment(); //Classe para anexar arquivos
            anexo1.setPath(e.getCaminhoAnexo()); //Incluindo diretrio do anexo
            anexo1.setDisposition(EmailAttachment.ATTACHMENT); //Informando um email que tem anexo
            email.attach(anexo1); //Atribuindo os anexos ao email
            email.send(); //envia o email
            System.out.println("Email Enviado com Sucesso !!!");
        } else {
            email.send(); //envia o email
            System.out.println("Email Enviado com Sucesso !!!");
        }
        return true;

    } catch (Exception ex) {
        return false;
    }
}

From source file:org.betaomega.finalmaveninvitationfx.GmailProvider.java

public void send(String address, String subject, String body, String invitationName, String invitationPath,
        String invitationMimeType) throws InvitationNotFoundException, UnsupportedEncodingException

{
    EmailAttachment attachment = new EmailAttachment();
    attachment.setPath(invitationPath);/*www .ja  va2  s.c om*/
    attachment.setDisposition(EmailAttachment.ATTACHMENT);
    attachment.setName(invitationName);
    MultiPartEmail email = new MultiPartEmail();
    email.setHostName("smtp.gmail.com");
    email.setSmtpPort(587);
    email.setAuthenticator(new DefaultAuthenticator(this.fromAddress, this.password));
    email.setStartTLSEnabled(true);

    email.setTLS(true);
    try {
        email.addTo(address);
    } catch (EmailException ex) {
        Logger.getLogger(Email.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        email.setFrom(this.fromAddress, this.fromName);
    } catch (EmailException ex) {
        Logger.getLogger(Email.class.getName()).log(Level.SEVERE, null, ex);
    }
    email.setSubject(subject);
    try {
        email.setMsg(body);
    } catch (EmailException ex) {
        Logger.getLogger(Email.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        email.attach(attachment);
    } catch (EmailException ex) {
        Logger.getLogger(Email.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        email.send();
    } catch (EmailException ex) {
        Logger.getLogger(Email.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:org.igov.io.mail.Mail.java

public void sendOld() throws EmailException {
    LOG.info("init");
    try {/*from w w  w.  ja va  2  s .c  om*/
        MultiPartEmail oMultiPartEmail = new MultiPartEmail();
        LOG.info("(getHost()={})", getHost());
        oMultiPartEmail.setHostName(getHost());

        String[] asTo = { sMailOnly(getTo()) };
        if (getTo().contains("\\,")) {
            asTo = getTo().split("\\,");//sTo
            for (String s : asTo) {
                LOG.info("oMultiPartEmail.addTo (s={})", s);
                oMultiPartEmail.addTo(s, "receiver");
            }
        }

        LOG.info("(getFrom()={})", getFrom());
        LOG_BIG.debug("(getFrom()={})", getFrom());
        oMultiPartEmail.setFrom(getFrom(), getFrom());//"iGov"
        oMultiPartEmail.setSubject(getHead());
        LOG.info("getHead()={}", getHead());
        String sLogin = getAuthUser();
        if (sLogin != null && !"".equals(sLogin.trim())) {
            oMultiPartEmail.setAuthentication(sLogin, getAuthPassword());
            LOG.info("withAuth");
        } else {
            LOG.info("withoutAuth");
        }
        //oMultiPartEmail.setAuthentication(getAuthUser(), getAuthPassword());
        LOG.info("(getAuthUser()={})", getAuthUser());
        //LOG.info("getAuthPassword()=" + getAuthPassword());
        oMultiPartEmail.setSmtpPort(getPort());
        LOG.info("(getPort()={})", getPort());
        oMultiPartEmail.setSSL(isSSL());
        LOG.info("(isSSL()={})", isSSL());
        oMultiPartEmail.setTLS(isTLS());
        LOG.info("(isTLS()={})", isTLS());

        oSession = oMultiPartEmail.getMailSession();
        MimeMessage oMimeMessage = new MimeMessage(oSession);

        //oMimeMessage.setFrom(new InternetAddress(getFrom(), "iGov", DEFAULT_ENCODING));
        oMimeMessage.setFrom(new InternetAddress(getFrom(), getFrom()));
        //oMimeMessage.addRecipient(Message.RecipientType.CC, new InternetAddress(sTo, sToName, DEFAULT_ENCODING));
        String sReceiverName = "receiver";
        if (asTo.length == 1) {
            sReceiverName = getToName();
        }
        for (String s : asTo) {
            LOG.info("oMimeMessage.addRecipient (s={})", s);
            //oMultiPartEmail.addTo(s, "receiver");
            oMimeMessage.addRecipient(Message.RecipientType.TO,
                    new InternetAddress(s, sReceiverName, DEFAULT_ENCODING));
        }

        //oMimeMessage.addRecipient(Message.RecipientType.TO,
        //        new InternetAddress(sTo, "recipient", DEFAULT_ENCODING));
        //new InternetAddress(getTo(), "recipient", DEFAULT_ENCODING));
        oMimeMessage.setSubject(getHead(), DEFAULT_ENCODING);

        _AttachBody(getBody());
        //LOG.info("(getBody()={})", getBody());
        oMimeMessage.setContent(oMultiparts);

        //            oMimeMessage.getRecipients(Message.RecipientType.CC);
        //methodCallRunner.registrateMethod(Transport.class.getName(), "send", new Object[]{oMimeMessage});
        Transport.send(oMimeMessage);
        LOG.info("Send " + getTo() + "!!!!!!!!!!!!!!!!!!!!!!!!");
    } catch (Exception oException) {
        LOG.error("FAIL: {} (getTo()={})", oException.getMessage(), getTo());
        LOG.trace("FAIL:", oException);
        throw new EmailException("Error happened when sending email (" + getTo() + ")" + "Exception message: "
                + oException.getMessage(), oException);
    }
    LOG.info("SUCCESS: Sent!");
}