Example usage for javax.activation FileDataSource FileDataSource

List of usage examples for javax.activation FileDataSource FileDataSource

Introduction

In this page you can find the example usage for javax.activation FileDataSource FileDataSource.

Prototype

public FileDataSource(String name) 

Source Link

Document

Creates a FileDataSource from the specified path name.

Usage

From source file:edu.harvard.i2b2.eclipse.plugins.fr.ws.FrServiceDriver.java

public static String sendSOAP(String[] attachmentfiles, String requestString, String type) throws Exception {

    /*// ww w  .j  a  v  a2s . c  o  m
    if(type != null){
       if(type.equals("FR"))
    System.setProperty("CRC_REQUEST", "URL: " + restEPR + "\n" + getCrc.toString());
       else 
    System.setProperty("FIND_REQUEST", "URL: " + restEPR + "\n" + getCrc.toString());
    }
     */
    MessageContext response = null;

    OMElement getCrc = getFrPayLoad(requestString);

    Options options = new Options();
    //         options.setTo( restEPR);
    //String serviceUrl = "http://phsi2b2appdev:8080/i2b2/services/FRService";
    if (serviceURL.endsWith("/"))
        serviceURL = serviceURL.substring(0, serviceURL.length() - 1);

    options.setTo(new EndpointReference(serviceURL));

    options.setAction("urn:sendfileRequest");
    options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

    // Increase the time out to receive large attachments
    options.setTimeOutInMilliSeconds(10000);

    options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);
    options.setProperty(Constants.Configuration.CACHE_ATTACHMENTS, Constants.VALUE_TRUE);
    options.setProperty(Constants.Configuration.ATTACHMENT_TEMP_DIR, "temp");
    options.setProperty(Constants.Configuration.FILE_SIZE_THRESHOLD, "4000");

    ServiceClient sender = FrServiceClient.getServiceClient();
    sender.setOptions(options);

    OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);

    MessageContext mc = new MessageContext();

    for (int i = 0; i < attachmentfiles.length; i++) {
        javax.activation.DataHandler dataHandler = new javax.activation.DataHandler(
                new FileDataSource(attachmentfiles[i]));

        mc.addAttachment("cid", dataHandler);
    }
    mc.setDoingSwA(true);

    //   OMElement requestElement = convertStringToOMElement(requestString);
    SOAPFactory sfac = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = sfac.getDefaultEnvelope();

    /*OMNamespace omNs = sfac.createOMNamespace(
    "http://www.i2b2.org/xsd", "swa");
    OMElement idEle = sfac.createOMElement("attchmentID", omNs);
    idEle.setText("cid");
            
    env.getBody().addChild(idEle);
     */
    env.getBody().addChild(getCrc);

    // SOAPEnvelope env = createEnvelope("fileattachment");
    mc.setEnvelope(env);
    mepClient.addMessageContext(mc);
    mepClient.execute(true);

    MessageContext inMsgtCtx = mepClient.getMessageContext("In");
    SOAPEnvelope responseEnv = inMsgtCtx.getEnvelope();

    OMElement soapResponse = responseEnv.getBody().getFirstElement();

    OMElement soapResult = soapResponse.getFirstElement();

    String i2b2Response = soapResponse.toString();

    MessageUtil.getInstance().setRequest("URL: " + serviceURL + "\n" + requestString);
    MessageUtil.getInstance().setResponse("URL: " + serviceURL + "\n" + response);

    return soapResponse.toString();
    //mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope().toStringWithConsume();

}

From source file:org.github.alexwibowo.opentext.client.AxiomVRDClient.java

@Override
public String storeDocument(String documentSource, Map<String, Object> sourceAttributes, String mimeType,
        File file) throws Exception {
    OMNamespace ns1 = factory.createOMNamespace("http://record.webservices.rd.vignette.com/", "");

    OMElement addRecordMappedElement = factory.createOMElement("addRecordMapped", ns1);

    OMElement licenseElement = factory.createOMElement("license", ns1);
    addRecordMappedElement.addChild(licenseElement);

    OMElement docSourceNameElement = factory.createOMElement("docSourceName", ns1);
    docSourceNameElement.setText(documentSource);
    addRecordMappedElement.addChild(docSourceNameElement);

    OMElement sourceVREFElement = factory.createOMElement("sourceVREF", ns1);
    sourceVREFElement.setText("");
    addRecordMappedElement.addChild(sourceVREFElement);

    for (Map.Entry<String, Object> attributeEntry : sourceAttributes.entrySet()) {
        addRecordMappedElement.addChild(createAttributeElement(factory, ns1, attributeEntry));
    }//from   w w w.  ja v a  2s .  com

    OMElement contentElement = factory.createOMElement("content", ns1);
    OMElement sectionIDElement = factory.createOMElement("sectionID", ns1);
    sectionIDElement.setText("1");
    contentElement.addChild(sectionIDElement);
    OMElement sectionDataElement = factory.createOMElement("sectionData", ns1);
    DataHandler dataHandler = new DataHandler(new FileDataSource(file));
    sectionDataElement.addChild(factory.createOMText(dataHandler, true));
    contentElement.addChild(sectionDataElement);
    OMElement renditionTypeElement = factory.createOMElement("renditionType", ns1);
    renditionTypeElement.setText(mimeType);
    contentElement.addChild(renditionTypeElement);

    addRecordMappedElement.addChild(contentElement);
    addRecordMappedElement.addChild(getOptionElement(factory, ns1));

    SOAPMessageBuilder soap11MessageBuilder = new AxiomSOAP11MessageBuilder(jaxbContext, soap11Factory)
            .withPayload(addRecordMappedElement)
            .withUsernameToken(configuration.getUsername(), configuration.getPassword());

    SOAPEnvelope envelope = (SOAPEnvelope) soap11MessageBuilder.build();
    HttpResponse httpResponse = postAsMultipart(envelope, VRDOperationQName.AddRecordMapped.getQName());

    dataHandler.getInputStream().close();

    if (httpResponse.getEntity() != null && httpResponse.getEntity().getContent() != null) {
        InputStream in = httpResponse.getEntity().getContent();
        Attachments attachments = new Attachments(in, httpResponse.getEntity().getContentType().getValue());
        SOAPEnvelope response = OMXMLBuilderFactory.createSOAPModelBuilder(attachments).getSOAPEnvelope();

        // retrieveContentResponse is addRecordMappedResponse
        OMElement addRecordMappedResponseElement = response.getBody().getFirstElement();

        // Unfortunately, our beautiful VRD responds with 'recDesc' in a null namespace. Hence if we use JAXB to unmarshall the response, we will get
        // null recDesc inside AddRecordMappedResponse object. such is life..
        OMElement recordDescElement = addRecordMappedResponseElement.getFirstElement();

        String recordID = recordDescElement.getFirstChildWithName(new QName("recordID")).getText();
        IOUtils.closeQuietly(in);
        return recordID;
    }
    return null;
}

From source file:org.openhealthtools.openxds.repository.filesystem.FileSystemRepositoryServiceImpl.java

public XdsRepositoryItem getRepositoryItem(String documentUniqueId, RepositoryRequestContext context)
        throws RepositoryException {
    XdsRepositoryItemImpl repositoryItem = null;
    // Strip off the "urn:uuid:"
    documentUniqueId = Utility.getInstance().stripId(documentUniqueId);
    try {/*  www . j  av a2 s  .c  om*/
        IActorDescription actorDescription = context.getActorDescription();
        if (actorDescription == null) {
            throw new RepositoryException("Missing required ActorDescription in RepositoryRequestContext");
        }

        CodeSet mimeTypeCodeSet = actorDescription.getCodeSet("mimeType");
        Set<Pair<String, String>> mimeTypes = mimeTypeCodeSet.getCodeSetKeys();
        String targetFileMimeType = null;
        File targetFile = null;

        //look up the file
        for (Pair<String, String> code : mimeTypes) {
            String mimeType = code.first;
            String ext = mimeTypeCodeSet.getExt(mimeType, null);
            File file = new File(repositoryRoot, documentUniqueId + "." + ext);
            if (file.exists()) {
                targetFileMimeType = mimeType;
                targetFile = file;
                if (log.isDebugEnabled())
                    log.debug("Repository File " + file.getPath() + " found");
            } else if (log.isDebugEnabled())
                log.debug("Repository File " + file.getPath() + " does not exist");
        }

        if (targetFile == null) {
            return null;
        }

        DataHandler contentDataHandler = new DataHandler(new FileDataSource(targetFile));
        repositoryItem = new XdsRepositoryItemImpl(documentUniqueId, contentDataHandler);
        repositoryItem.setMimeType(targetFileMimeType);

    } catch (Exception e) {
        throw new RepositoryException(e);
    }
    return repositoryItem;

}

From source file:frameworkcontentspeed.Utils.SendEmailAtachament.java

public static void SendEmailPassed(String from, String to1, String subject, String filename)
        throws FileNotFoundException, IOException {

    try {/*from ww w.ja  v a2 s.  co m*/

        //Get properties object    
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");
        //get Session   
        Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(from, "anda.cristea");
            }
        });
        //compose message    
        try {
            MimeMessage message = new MimeMessage(session);
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to1));
            //message.addRecipient(Message.RecipientType.BCC, new InternetAddress(grupSephora));

            message.setSubject(subject);
            // message.setText(msg);

            BodyPart messageBodyPart = new MimeBodyPart();

            messageBodyPart.setText("Raport teste automate");

            Multipart multipart = new MimeMultipart();

            multipart.addBodyPart(messageBodyPart);

            messageBodyPart = new MimeBodyPart();

            DataSource source = new FileDataSource(filename);

            messageBodyPart.setDataHandler(new DataHandler(source));

            messageBodyPart.setFileName(filename);

            multipart.addBodyPart(messageBodyPart);

            message.setContent(multipart);

            //send message  
            Transport.send(message);
            System.out.println("message sent successfully");
        } catch (Exception ex) {
            System.out.println("eroare trimitere email-uri");
            System.out.println(ex.getMessage());

        }

    } catch (Exception ex) {
        System.out.println("eroare trimitere email-uri");
        System.out.println(ex.getMessage());

    }

}

From source file:com.manydesigns.mail.sender.DefaultMailSender.java

protected void send(Email emailBean) throws EmailException {
    logger.debug("Entering send(Email)");
    org.apache.commons.mail.Email email;
    String textBody = emailBean.getTextBody();
    String htmlBody = emailBean.getHtmlBody();
    if (null == htmlBody) {
        if (emailBean.getAttachments().isEmpty()) {
            SimpleEmail simpleEmail = new SimpleEmail();
            simpleEmail.setMsg(textBody);
            email = simpleEmail;/*from  w w  w.  j av  a2 s  .  c om*/
        } else {
            MultiPartEmail multiPartEmail = new MultiPartEmail();
            multiPartEmail.setMsg(textBody);
            for (Attachment attachment : emailBean.getAttachments()) {
                EmailAttachment emailAttachment = new EmailAttachment();
                emailAttachment.setName(attachment.getName());
                emailAttachment.setDisposition(attachment.getDisposition());
                emailAttachment.setDescription(attachment.getDescription());
                emailAttachment.setPath(attachment.getFilePath());
                multiPartEmail.attach(emailAttachment);
            }
            email = multiPartEmail;
        }
    } else {
        HtmlEmail htmlEmail = new HtmlEmail();
        htmlEmail.setHtmlMsg(htmlBody);
        if (textBody != null) {
            htmlEmail.setTextMsg(textBody);
        }
        for (Attachment attachment : emailBean.getAttachments()) {
            if (!attachment.isEmbedded()) {
                EmailAttachment emailAttachment = new EmailAttachment();
                emailAttachment.setName(attachment.getName());
                emailAttachment.setDisposition(attachment.getDisposition());
                emailAttachment.setDescription(attachment.getDescription());
                emailAttachment.setPath(attachment.getFilePath());
                htmlEmail.attach(emailAttachment);
            } else {
                FileDataSource dataSource = new FileDataSource(new File(attachment.getFilePath()));
                htmlEmail.embed(dataSource, attachment.getName(), attachment.getContentId());
            }
        }
        email = htmlEmail;
    }

    if (null != login && null != password) {
        email.setAuthenticator(new DefaultAuthenticator(login, password));
    }
    email.setHostName(server);
    email.setSmtpPort(port);
    email.setSubject(emailBean.getSubject());
    email.setFrom(emailBean.getFrom());
    // hongliangpan add
    if ("smtp.163.com".equals(server)) {
        email.setFrom(login + "@163.com");
        // email.setAuthenticator(new DefaultAuthenticator("test28797575", "1qa2ws3ed"));
    }

    for (Recipient recipient : emailBean.getRecipients()) {
        switch (recipient.getType()) {
        case TO:
            email.addTo(recipient.getAddress());
            break;
        case CC:
            email.addCc(recipient.getAddress());
            break;
        case BCC:
            email.addBcc(recipient.getAddress());
            break;
        }
    }
    email.setSSL(ssl);
    email.setTLS(tls);
    email.setSslSmtpPort(port + "");
    email.setCharset("UTF-8");
    email.send();
    logger.debug("Exiting send(Email)");
}

From source file:org.onesec.raven.ivr.vmail.impl.VMailManagerNodeTest.java

@Test
public void sendCdrTest() throws Exception {
    DataCollector collector = createDataCollector();
    VMailCdrRecordSchema schema = createRecordSchema();
    manager.setRecordSchema(schema);//from  w w  w . java2 s . c  om

    VMailBoxNode vbox = createVBox(manager, "vbox1", true);
    createVBoxNumber(vbox, "111", true);
    assertTrue(manager.start());

    File testFile = createTestFile();
    Date messageDate = new Date();
    ds.pushData(new NewVMailMessageImpl("111", "222", messageDate, new FileDataSource(testFile)));

    assertEquals(1, collector.getDataListSize());
    assertTrue(collector.getDataList().get(0) instanceof Record);
    Record rec = (Record) collector.getDataList().get(0);
    assertSame(vbox, rec.getTag(VMailManagerNode.VMAIL_BOX_TAG));
    assertTrue(rec.getTag(VMailManagerNode.VMAIL_MESSAGE_TAG) instanceof DataSource);
    assertEquals(new Long(vbox.getId()), rec.getValue(VMailCdrRecordSchema.VMAIL_BOX_ID));
    assertEquals("111", rec.getValue(VMailCdrRecordSchema.VMAIL_BOX_NUMBER));
    assertEquals("222", rec.getValue(VMailCdrRecordSchema.SENDER_PHONE_NUMBER));
    assertEquals(messageDate, rec.getValue(VMailCdrRecordSchema.MESSAGE_DATE));
}

From source file:it.cnr.icar.eric.client.xml.registry.util.CertificateUtil.java

@SuppressWarnings("static-access")
private static Certificate[] getCertificateSignedByRegistry(LifeCycleManager lcm, X509Certificate inCert)
        throws JAXRException {
    Certificate[] certChain = new Certificate[2];

    try {/*  w  ww . ja  v  a2s . c o m*/
        // Save cert in a temporary keystore file which is sent as
        // repository item to server so it can be signed
        KeyStore tmpKeystore = KeyStore.getInstance("JKS");
        tmpKeystore.load(null, bu.FREEBXML_REGISTRY_KS_PASS_REQ.toCharArray());

        tmpKeystore.setCertificateEntry(bu.FREEBXML_REGISTRY_USERCERT_ALIAS_REQ, inCert);
        File repositoryItemFile = File.createTempFile(".eric-ca-req", ".jks");
        repositoryItemFile.deleteOnExit();
        FileOutputStream fos = new java.io.FileOutputStream(repositoryItemFile);
        tmpKeystore.store(fos, bu.FREEBXML_REGISTRY_KS_PASS_REQ.toCharArray());
        fos.flush();
        fos.close();

        // Now have server sign the cert using extensionRequest
        javax.activation.DataHandler repositoryItem = new DataHandler(new FileDataSource(repositoryItemFile));
        String id = it.cnr.icar.eric.common.Utility.getInstance().createId();
        HashMap<String, Object> idToRepositoryItemsMap = new HashMap<String, Object>();
        idToRepositoryItemsMap.put(id, repositoryItem);

        HashMap<String, String> slotsMap = new HashMap<String, String>();
        slotsMap.put(BindingUtility.FREEBXML_REGISTRY_PROTOCOL_SIGNCERT, "true");

        RegistryRequestType req = bu.rsFac.createRegistryRequestType();
        bu.addSlotsToRequest(req, slotsMap);

        RegistryResponseHolder respHolder = ((LifeCycleManagerImpl) lcm).extensionRequest(req,
                idToRepositoryItemsMap);
        DataHandler responseRepositoryItem = (DataHandler) respHolder.getAttachmentsMap().get(id);

        InputStream is = responseRepositoryItem.getInputStream();
        KeyStore keyStore = KeyStore.getInstance("JKS");
        keyStore.load(is, bu.FREEBXML_REGISTRY_KS_PASS_RESP.toCharArray());
        is.close();

        certChain[0] = keyStore.getCertificate(bu.FREEBXML_REGISTRY_USERCERT_ALIAS_RESP);
        if (certChain[0] == null) {
            throw new JAXRException(JAXRResourceBundle.getInstance().getString("message.CannotFindUserCert"));
        }
        certChain[1] = keyStore.getCertificate(bu.FREEBXML_REGISTRY_CACERT_ALIAS);
        if (certChain[1] == null) {
            throw new JAXRException(JAXRResourceBundle.getInstance().getString("message.CannotFindCARootCert"));
        }
    } catch (Exception e) {
        throw new JAXRException(JAXRResourceBundle.getInstance().getString("message.CertSignFailed"), e);
    }

    return certChain;
}

From source file:annis.gui.ReportBugWindow.java

private boolean sendBugReport(String bugEMailAddress, byte[] screenImage, String imageMimeType) {
    MultiPartEmail mail = new MultiPartEmail();
    try {//w w w.  j a v a2s. c o  m
        // server setup
        mail.setHostName("localhost");

        // content of the mail
        mail.addReplyTo(form.getField("email").getValue().toString(),
                form.getField("name").getValue().toString());
        mail.setFrom(bugEMailAddress);
        mail.addTo(bugEMailAddress);

        mail.setSubject("[ANNIS BUG] " + form.getField("summary").getValue().toString());

        // TODO: add info about version etc.
        StringBuilder sbMsg = new StringBuilder();

        sbMsg.append("Reporter: ").append(form.getField("name").getValue().toString()).append(" (")
                .append(form.getField("email").getValue().toString()).append(")\n");
        sbMsg.append("Version: ").append(VaadinSession.getCurrent().getAttribute("annis-version")).append("\n");
        sbMsg.append("URL: ").append(UI.getCurrent().getPage().getLocation().toASCIIString()).append("\n");

        sbMsg.append("\n");

        sbMsg.append(form.getField("description").getValue().toString());
        mail.setMsg(sbMsg.toString());

        if (screenImage != null) {
            try {
                mail.attach(new ByteArrayDataSource(screenImage, imageMimeType), "screendump.png",
                        "Screenshot of the browser content at time of bug report");
            } catch (IOException ex) {
                log.error(null, ex);
            }

            File logfile = new File(VaadinService.getCurrent().getBaseDirectory(),
                    "/WEB-INF/log/annis-gui.log");
            if (logfile.exists() && logfile.isFile() && logfile.canRead()) {
                mail.attach(new FileDataSource(logfile), "annis-gui.log",
                        "Logfile of the GUI (shared by all users)");
            }
        }

        mail.send();
        return true;

    } catch (EmailException ex) {
        Notification.show("E-Mail not configured on server",
                "If this is no Kickstarter version please ask the adminstrator of this ANNIS-instance for assistance. "
                        + "Bug reports are not available for ANNIS Kickstarter",
                Notification.Type.ERROR_MESSAGE);
        log.error(null, ex);
        return false;
    }
}

From source file:org.wso2.carbon.connector.integration.test.apns.PushNotificationIntegrationTest.java

/**
 * Test case to verify that the connector works only with mandatory
 * parameters./* ww  w  .java  2 s.  co  m*/
 * 
 * @throws Exception
 */
@Test(groups = {
        "org.wso2.carbon.connector.apns" }, priority = 1, description = "Integration test to cover mandatory parameters.")
public void testSendPushNotificationWithMandatoryParams() throws Exception {

    // Add proxy service
    String proxyServiceName = "apns_push";

    URL proxyUrl = new URL(
            "file:" + File.separator + File.separator + ProductConstant.SYSTEM_TEST_RESOURCE_LOCATION
                    + ConnectorIntegrationUtil.ESB_CONFIG_LOCATION + File.separator + "proxies" + File.separator
                    + CONNECTOR_NAME + File.separator + proxyServiceName + ".xml");

    proxyAdmin.addProxyService(new DataHandler(proxyUrl));

    // Construct and send the request.

    String environment = PushNotificationRequest.SANDBOX_DESTINATION;
    String certificateAttachmentName = "certificate";
    String password = apnsProperties.getProperty(PROPERTY_KEY_CERTIFICATE_PASSWORD);

    String deviceToken = apnsProperties.getProperty(PROPERTY_KEY_DEVICE_TOKEN);

    String requestTemplate = ConnectorIntegrationUtil.getRequest("with_mandatory_params");
    String request = String.format(requestTemplate, environment, certificateAttachmentName, password,
            deviceToken);
    OMElement requestEnvelope = AXIOMUtil.stringToOM(request);

    String certificateFileName = apnsProperties.getProperty(PROPERTY_KEY_APNS_CERTIFICATE_FILENAME);
    Map<String, DataHandler> attachmentMap = new HashMap<String, DataHandler>();
    attachmentMap
            .put(certificateAttachmentName,
                    new DataHandler(new FileDataSource(new File(ProductConstant.SYSTEM_TEST_RESOURCE_LOCATION
                            + ConnectorIntegrationUtil.ESB_CONFIG_LOCATION + File.separator + "auth"
                            + File.separator + certificateFileName))));

    OperationClient mepClient = ConnectorIntegrationUtil.buildMEPClientWithAttachment(
            new EndpointReference(getProxyServiceURL(proxyServiceName)), requestEnvelope, attachmentMap);

    // Test the result.
    try {
        mepClient.execute(true);

        MessageContext responseMsgCtx = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);

        OMElement resultParentTag = responseMsgCtx.getEnvelope().getBody()
                .getFirstChildWithName(new QName(NS_URI_APNS, TAG_DISPATCH_TO_DEVICE_RESULT));

        OMElement successfulTag = resultParentTag.getFirstChildWithName(new QName(NS_URI_APNS, TAG_SUCCESSFUL));
        Assert.assertEquals("true", successfulTag.getText());

    } finally {
        proxyAdmin.deleteProxy(proxyServiceName);
    }
}

From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java

/**
 * Se encarga de enviar el mensaje de correo electronico *
 *//*w  w w. j av a 2  s .  co m*/
public static Boolean sendEmail(final EmailMessage emdto) throws BusinessException {
    try {
        Session session;
        Properties properties = System.getProperties();
        properties.put("mail.host", emdto.getHost());
        properties.put("mail.transport.protocol", "smtp");
        properties.put("mail.smtp.port", emdto.getPort());
        properties.put("mail.smtp.starttls.enable", emdto.getStarttls());
        if (emdto.getUser() != null && emdto.getPassword() != null) {
            properties.put("mail.smtp.auth", "true");
            session = Session.getDefaultInstance(properties, new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(emdto.getUser(), emdto.getPassword());
                }
            });
        } else {
            properties.put("mail.smtp.auth", "false");
            session = Session.getDefaultInstance(properties);
        }

        message = new MimeMessage(session);
        message.setFrom(new InternetAddress(emdto.getFrom(), emdto.getMask()));
        message.setSubject(emdto.getSubject());

        for (String to : emdto.getToList()) {
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        }
        if (emdto.getCcList() != null) {
            for (String cc : emdto.getCcList()) {
                message.addRecipient(Message.RecipientType.CC, new InternetAddress(cc));
            }
        }
        if (emdto.getCcoList() != null) {
            for (String cco : emdto.getCcoList()) {
                message.addRecipient(Message.RecipientType.BCC, new InternetAddress(cco));
            }
        }

        bodyPart = new MimeBodyPart();
        bodyPart.setContent(emdto.getBodyMessage(), emdto.getMimeTypeMessage());
        multipart = new MimeMultipart();
        multipart.addBodyPart(bodyPart);

        if (emdto.getFilePaths() != null) {
            for (String filePath : emdto.getFilePaths()) {
                File file = new File(filePath);
                if (file.exists()) {
                    dataSource = new FileDataSource(file);
                    bodyPart = new MimeBodyPart();
                    bodyPart.setDataHandler(new DataHandler(dataSource));
                    bodyPart.setFileName(file.getName());
                    multipart.addBodyPart(bodyPart);
                }
            }
        }

        message.setContent(multipart);
        Transport.send(message);
    } catch (MessagingException | UnsupportedEncodingException ex) {
        Logger.getLogger(BusinessUtils.class.getName()).log(Level.SEVERE, "BusinessUtils.sendEmail Exception",
                ex);
        throw new BusinessException(ex);
    }
    return Boolean.TRUE;
}