Mail samples

Basics

Example of UUID:

  • Using UUID -> "064ff51a-b815-4f48-a096-b4946876784f";

Suggested code sample

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

Then you should log in using the method "login". You can access the "login" method from the webservice object "ws" as shown below:

ws.login(user, password);

Once you are logged in with the webservices, the session is kept in the webservice object. Then you can use the other API methods.

At this point you can use all the Mail methods from "mail" class as shown below:

ws.mail.getProperties("05d9b8e3-f9c1-4ace-9007-afd775dbbced")

Methods

getProperties

Description:

Method Return values Description

getProperties(String uuid)

Mail

Returns the mail properties.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.mail.getProperties("05d9b8e3-f9c1-4ace-9007-afd775dbbced"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

delete

Description:

Method Return values Description

delete(String uuid)

void

Deletes a mail.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.mail.delete("05d9b8e3-f9c1-4ace-9007-afd775dbbced");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

purge

Description:

Method Return values Description

purge(String uuid)

void

Mail is permanently removed from the repository.

Usually, you will purge mails to /okm:trash/userId - the user's personal trash location - but it is possible to directly purge any mail from the entire repository.

When a mail is purged, it can only be restored from a previous repository backup. The purge action permanently removes the mail from the repository.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.mail.purge("05d9b8e3-f9c1-4ace-9007-afd775dbbced");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

rename

Description:

Method Return values Description

rename(String uuid, String newName)

void

Renames a mail.

In the OpenKM frontend UI, the subject is used to display the mail name in the file browser table. That means this change will take effect internally on the mail path, but will not be reflected in the default UI.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.mail.rename("e3831cc4-30f0-419a-8fbf-a3418472ada5", "new name");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

move

Description:

Method Return values Description

move(String uuid, String dstId)

void

Moves a mail into a folder or record.

The values of the dstId parameter should be a folder or record UUID.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.mail.move("e3831cc4-30f0-419a-8fbf-a3418472ada5", "ada67d44-b081-4b23-bdc1-74181cafbc5d");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

copy

Description:

Method Return values Description

public void copy(String uuid, String dstId, String newName)

void

Copies a mail into a folder or record.

The values of the dstId parameter should be a folder or record UUID.

When the newName parameter value is null, the mail will preserve the same name.

Only the security grants are copied to the destination, the metadata, keywords, etc. of the folder are not copied.

See "extendedCopy" method for this feature.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.mail.copy("e3831cc4-30f0-419a-8fbf-a3418472ada5", "ada67d44-b081-4b23-bdc1-74181cafbc5d", "new_name");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

extendedCopy

Description:

Method Return values Description

extendedCopy(String uuid, String dstId, boolean categories, boolean keywords, boolean propertyGroups, boolean notes, boolean security, String newName)

Mail

Copies a mail with associated data into a folder or record.

The values of the dstId parameter should be a folder or record UUID.

By default, only the binary data and the security grants are copied; the metadata, keywords, etc. are not copied.

Additional:

  • When the categories parameter is true, the original values of the categories will be copied.
  • When the keywords parameter is true, the original values of the keywords will be copied.
  • When the propertyGroups parameter is true, the original values of the metadata groups will be copied.
  • When the notes parameter is true, the original values of the notes will be copied.
  • When the security parameter is true, the original security grants will be copied.
  • When newName is set, the mail's name is changed.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Mail;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Mail mail = ws.mail.extendedCopy("e3831cc4-30f0-419a-8fbf-a3418472ada5", "ada67d44-b081-4b23-bdc1-74181cafbc5d", true, true, true, true, true, null);
            System.out.println(mail);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getChildren

Description:

Method Return values Description

 getChildren(String uuid)

List<Mail>

Returns a list of all mails whose parent is fldId.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Mail;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (Mail mail : ws.mail.getChildren("ada67d44-b081-4b23-bdc1-74181cafbc5d")) {
                System.out.println(mail);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

isValid

Description:

Method Return values Description

isValid(String uuid)

Boolean

Returns a boolean that indicates if the node is a mail or not.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            // Return false
            System.out.println(ws.mail.isValid("ada67d44-b081-4b23-bdc1-74181cafbc5d"));

            // Return true
            System.out.println(ws.mail.isValid("e3831cc4-30f0-419a-8fbf-a3418472ada5"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPath

Description:

Method Return values Description

getPath(String uuid)

String

Converts mail UUID to mail path.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.mail.getPath("e3831cc4-30f0-419a-8fbf-a3418472ada5"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createAttachment

Description:

Method Return values Description

createAttachment(String uuid, String docName, InputStream is)

Document

Adds an attachment to the mail.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            InputStream is = new FileInputStream("/home/openkm/logo.png");
            ws.mail.createAttachment("e3831cc4-30f0-419a-8fbf-a3418472ada5", "logo.png", is);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteAttachment

Description:

Method Return values Description

deleteAttachment(String uuid, String docId)

void

Deletes a mail attachment.

The value of the docId parameter can be a valid document UUID.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.mail.deleteAttachment("e3831cc4-30f0-419a-8fbf-a3418472ada5", "6dcb02dc-0881-4610-b2bc-a158ed7be0ee");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getAttachments

Description:

Method Return values Description

getAttachments(String uuid)

List<Document>

Retrieves a list of all attachment documents of the mail.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (Document doc : ws.mail.getAttachments("e3831cc4-30f0-419a-8fbf-a3418472ada5")) {
                System.out.println(doc);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

sendMailWithAttachments

Description:

Method Return values Description

sendMailWithAttachments(List<String> to, List<String> cc, List<String> bcc, List<String> replyTo, String subject, String body, List<String> docsId, String uuid)

void

Sends a mail message with attachments.

The value of the uuid parameter should be a folder or record UUID. The uuid parameter indicates where the mail will be stored in the repository after it is sent.

Other parameters:

  • to is a list of destination email accounts.
  • subject is the mail subject.
  • cc, bcc, replyTo are lists of destination email accounts (optional)
  • docsId is a list of valid document UUIDs already in OpenKM that will be sent as attachments in the mail (optional).

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            List<String> to = Arrays.asList("gnu.java.sergio@mail.com");
            List<String> cc = new ArrayList<>();
            List<String> bcc = new ArrayList<>();
            List<String> replyTo = new ArrayList<>();
            List<String> docsId = Arrays.asList("46762f90-82c6-4886-8d21-ad3017dd78a7", "8cd1e072-8595-4dd3-b121-41d622c43f08");
            ws.mail.sendMailWithAttachments(to, cc, bcc, replyTo, "some subject", "some body", docsId, "85f07f05-1641-47e8-891f-0ea30643554e");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

sendMailWithAttachments

Description:

Method Return values Description

sendMailWithAttachments(String from, List<String> to, List<String> cc, List<String> bcc, List<String> replyTo, String subject, String body, List<String> docsId, String uuid)

void

Sends a mail message with attachments.

The value of the uuid parameter should be a folder or record UUID. The uuid parameter indicates where the mail will be stored in the repository after it is sent.

Other parameters:

  • from is optional and may be set to an empty value
  • to is a list of destination email accounts.
  • subject is the mail subject.
  • cc, bcc, replyTo are lists of destination email accounts (optional)
  • docsId is a list of valid document UUIDs already in OpenKM that will be sent as attachments in the mail (optional).

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            String from = "some@nomail.com";
            List<String> to = Arrays.asList("gnu.java.sergio@mail.com");
            List<String> cc = new ArrayList<>();
            List<String> bcc = new ArrayList<>();
            List<String> replyTo = new ArrayList<>();
            List<String> docsId = Arrays.asList("46762f90-82c6-4886-8d21-ad3017dd78a7", "8cd1e072-8595-4dd3-b121-41d622c43f08");
            ws.mail.sendMailWithAttachments(from, to, cc, bcc, replyTo, "some subject", "some body", docsId, "85f07f05-1641-47e8-891f-0ea30643554e");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

importEml

Description:

Method Return values Description

importEml(String uuid, String title, InputStream is)

Mail

Imports a mail in EML format.

The value of the uuid parameter should be a folder or record UUID. The uuid parameter indicates where the mail will be stored in the repository after it is imported.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Mail;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            InputStream is = new FileInputStream("/home/openkm/test.eml");
            Mail mail = ws.mail.importEml("85f07f05-1641-47e8-891f-0ea30643554e", "some title", is);
            System.out.println(mail);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

importMsg

Description:

Method Return values Description

importMsg(String uuid, String title, InputStream is)

Mail

Imports a mail in MSG format.

The value of the uuid parameter should be a folder or record UUID. The uuid parameter indicates where the mail will be stored in the repository after it is imported.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Mail;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            InputStream is = new FileInputStream("/home/openkm/test.msg");
            Mail mail = ws.mail.importMsg("85f07f05-1641-47e8-891f-0ea30643554e", "some title", is);
            System.out.println(mail);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setTitle

Description:

Method Return values Description

setTitle(String uuid, String title)

void

Sets the mail title.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.mail.setTitle("9d5dd110-db99-4d72-8cf7-610b027a4822", "new title");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

sendMail

Description:

Method Return values Description

sendMail(List<String> recipients, String subject, String body)

void

Sends a mail.

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.List;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            StringBuffer body = new StringBuffer();
            body.append("Test message body.");
            List<String> recipients = new ArrayList<>();
            recipients.add("some@mail.com");
            ws.mail.sendMail(recipients, "Testing sending mail from OpenKM", body.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

sendMail

Description:

Method Return values Description

sendMail(String from, List<String> recipients, String subject, String body)

void

Sends a mail.

Other parameters:

  • from is optional and maybe set with empty value

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.List;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            String from = "some@nomail.com";
            StringBuffer body = new StringBuffer();
            body.append("Test message body.");
            List<String> recipients = new ArrayList<>();
            recipients.add("some@mail.com");
            ws.mail.sendMail(to, recipients, "Testing sending mail from OpenKM", body.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

sendMail

Description:

Method Return values Description

sendMail(String to, String subject, String body)

void

Send a mail.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Test {

    private static final Logger log = LoggerFactory.getLogger(Test.class);

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            // sendMail
            String to = "some@nomail.com";
            StringBuffer body = new StringBuffer();
            body.append("message test");
            ws.mail.sendMail(to, "sigma subject", body.toString());
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
}

setDispositionStage

Description:

Method Return values Description

setDispositionStage(String uuid, long stage)

void

Set the disposition stage

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            long stage = 1;
            ws.mail.setDispositionStage("7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", stage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setDescription

Description:

Method Return values Description

setDescription(String uuid, String description)

void

Set the description.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Mail;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.mail.setDescription("b405a504-d8cb-4166-ac51-22f68acee8c5", "some description");
            Mail mail = ws.mail.getProperties("b405a504-d8cb-4166-ac51-22f68acee8c5");
            System.out.println("Description: " + mail.getDescription());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getContent

Description:

Method Return values Description

getContent(String mailId)

InputStream

Retrieves the mail content (binary data) of the current mail version.

Example:

package com.openkm;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            OutputStream fos = new FileOutputStream("/home/openkm/test.eml");
            InputStream is = ws.mail.getContent("b405a504-d8cb-4166-ac51-22f68acee8c5");
            IOUtils.copy(is, fos);
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createWizard

Description:

Method Return values Description

createMail(String uuid, String title, InputStream is, String type)

WizardNode

Creates a new document with a wizard.

The parameter uuid should be a valid folder or record UUID.

Available types:

  • Mail.ORIGIN_MSG
  • Mail.ORIGIN_EML

The WizardNode contains a list of pending actions that should be done to complete the document creation process. These might be:

  • Add keyword
  • Add Categories
  • Add Metadata

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Mail;
import com.openkm.sdk4j.bean.WizardNode;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            InputStream is = new FileInputStream("/home/openkm/sample2.eml");
            WizardNode wn = ws.mail.createWizardl("4c195453-246b-4ce9-86ba-b84e68d1f284", "test title", is, Mail.ORIGIN_EML);
            System.out.print(wn);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getThumbnail

Description:

Method Return values Description

getThumbnail(String mailId, ThumbnailType type)

InputStream

Returns thumbnail image data.

Available types:

  • ThumbnailType.THUMBNAIL_PROPERTIES ( shown in properties view )
  • ThumbnailType.THUMBNAIL_LIGHTBOX ( shown in light box )
  • ThumbnailType.THUMBNAIL_SEARCH ( shown in search view )

Each thumbnail type has its own image dimensions.

Example:

package com.openkm;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.ThumbnailType;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            OutputStream fos = new FileOutputStream("/home/gnujavasergio/okm/thumbnail.png");
            InputStream is = ws.mail.getMailThumbnail("1778f0b5-672c-48c1-b54e-494c18dd6df4", ThumbnailType.THUMBNAIL_LIGHTBOX);
            IOUtils.copy(is, fos);
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getMailsPaginated

Description:

Method Return values Description

getMailsPaginated(String context, int offset, int limit, MailFilterQuery filter, String orderColumn, boolean orderAsc) 

SimpleNodeBaseResultSet

Returns a paginated list of emails filtered by the values of the MailFilterQuery parameter.

The parameters "limit" and "offset" allow you to retrieve just a portion of the results of a query.

  • The parameter "limit" is used to limit the number of results returned.
  • The parameter "offset" specifies how many results to skip before beginning to return results.
  • The parameter "orderColumn" can have the following values: uuid, subject, from, sentDate and hasAttachments.
  • The parameter "orderAsc" can be "true" in case of ascending order and "false" otherwise.

For example, if your query has 1000 results, but you only want to return the first 10, you should use these values:

  • limit=10
  • offset=0

Now suppose you want to show the results from 11-20, you should use these values:

  • limit=10
  • offset=10

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.AttachmentEnum;
import com.openkm.sdk4j.bean.MailFilterQuery;
import com.openkm.sdk4j.bean.SimpleNodeBase;
import com.openkm.sdk4j.bean.SimpleNodeBaseResultSet;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            MailFilterQuery filter = new MailFilterQuery();
            filter.setSubject("");
            filter.setAttachments(AttachmentEnum.ALL);
            String orderColumn = "subject";
            SimpleNodeBaseResultSet simpleNodeBaseResultSet = ws.mail.getMailsPaginated("/okm:root", 0, 20, filter, orderColumn, true);

            for (SimpleNodeBase simpleNodeBase : simpleNodeBaseResultSet.getResults()) {
                System.out.println(simpleNodeBase);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getAccounts

Description:

Method Return values Description

getAccounts()

List<MailAccount>

Retrieves a list of user email accounts.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.MailAccount;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (MailAccount mailAccount : ws.mail.getAccounts()) {
                System.out.println(mailAccount);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getMailMessages

Description:

Method Return values Description

getMailMessages(long accountId, long start)

MailServerMessages

Retrieves a list of messages on the email server for an email account.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.ExternalMail;
import com.openkm.sdk4j.bean.MailServerMessages;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            long accoundId = 1;
            long start = 1;
            MailServerMessages msg = ws.mail.getMailMessages(accoundId, start);
            for (ExternalMail mail : msg.getServerMails()) {
                System.out.println(mail);
            }

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

addAccount

Description:

Method Return values Description

addAccount(MailAccount mailAccount)

void

Adds an email account.

It is good practice to create an account and verify the mail configuration with testMailAccount(MailAccount mail).

When you do not set the user, the account will be added by default to the logged-in user.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.MailAccount;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            MailAccount mailAcount = new MailAccount();
            mailAcount.setMailProtocol(MailAccount.PROTOCOL_IMAPS);
            mailAcount.setMailUser("test@none.com");
            mailAcount.setMailPassword("123456");
            mailAcount.setMailHost("imap.gmail.com");
            mailAcount.setMailFolder("OpenKM");
            mailAcount.setActive(true);
            mailAcount.setRecursive(true);
            ws.mail.addAccount(mailAcount);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

updateAccount

Description:

Method Return values Description

updateAccount(MailAccount mailAccount)

void

Updates the main configuration data of an email account.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.MailAccount;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            MailAccount mailAcount = new MailAccount();
            mailAcount.setId(2);
            mailAcount.setMailProtocol(MailAccount.PROTOCOL_IMAPS);
            mailAcount.setMailUser("testupdate@none.com");
            mailAcount.setMailPassword("123456789");
            mailAcount.setMailHost("imap.gmail.com");
            mailAcount.setMailFolder("OpenKM");
            mailAcount.setActive(true);
            mailAcount.setRecursive(true);
            ws.mail.updateAccount(mailAcount);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

testAccount

Description:

Method Return values Description

testAccount(MailAccount mailAccount)

void

Checks the email account connection.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.MailAccount;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            MailAccount mailAcount = new MailAccount();
            mailAcount.setMailProtocol(MailAccount.PROTOCOL_IMAPS);
            mailAcount.setMailUser("testupdate@none.com");
            mailAcount.setMailPassword("123456789");
            mailAcount.setMailHost("imap.gmail.com");
            mailAcount.setMailFolder("OpenKM");
            mailAcount.setActive(true);
            mailAcount.setRecursive(true);

            // Test mail account
            ws.mail.testAccount(mailAcount);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteAccount

Description:

Method Return values Description

deleteAccount(long mailAccountId)

void

Deletes an email account.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            long mailAccountId = 2;
            ws.mail.deleteAccount(mailAccountId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

importMessages

Description:

Method Return values Description

importMessages(long mailAccountId, List<Long> messageIds)

void

Imports messages from an email account.

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.List;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.ExternalMail;
import com.openkm.sdk4j.bean.MailServerMessages;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            List<Long> messageIds = new ArrayList<>();

            long mailAccountId = 1; // Valid mailAccountId
            long start = 1;
            MailServerMessages msg = ws.mail.getMailMessages(mailAccountId, start);
            for (ExternalMail mail : msg.getServerMails()) {
                messageIds.add(mail.getUid());
            }

            ws.mail.importMailMessages(mailAccountId, messageIds);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createFilter

Description:

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.MailFilter;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            long mailAccountId = 2; // Valid mailAccountId

            MailFilter filter = new MailFilter();
            filter.setOrder(0);
            filter.setGrouping(false);
            filter.setExclusive(true);
            filter.setActive(false);
            filter.setNode("a9d5c158-c7b1-4771-b9c3-b8d24f5a2645");

            ws.mail.createFilter(mailAccountId, filter);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

updateFilter

Description:

Method Return values Description

createFilter(long mailAccountId, MailFilter mailFilter)

void

Adds an email account filter.

Method Return values Description

updateFilter(MailFilter mailFilter)

void

Update an email account filter.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.MailFilter;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);

            MailFilter filter = new MailFilter();
            filter.setId(2);  // Valid filter id
            filter.setOrder(0);
            filter.setGrouping(false);
            filter.setExclusive(true);
            filter.setActive(true);
            filter.setNode("a9d5c158-c7b1-4771-b9c3-b8d24f5a2645");

            ws.mail.updateFilter(filter);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteFilter

Description:

Method Return values Description

deleteFilter(long mailFilterId)

void

Delete an email account filter.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);

            long filterId = 1; // Valid filter id
            ws.mail.deleteFilter(filterId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createRule

Description:

Method Return values Description

createRule(long filterId, MailFilterRule rule)

void

Create an email filter rule.


 Mail account filter parameters:

  • Field:           Sets the mail field that will be evaluated by the rule.

 

Available options are: 

  • MailFilterRule.FIELD_FROM
  • MailFilterRule.FIELD_TO
  • MailFilterRule.FIELD_SUBJECT
  • MailFilterRule.FIELD_CONTENT
  • MailFilterRule.FIELD_ATTACHMENT              

 

  • Operation:  Set the operation that will be performed during the evaluation process.

 

Available options are:

  • MailFilterRule.OPERATION_EQUALS
  • MailFilterRule.OPERATION_NOT_EQUALS
  • MailFilterRule.OPERATION_CONTAINS
  • MailFilterRule.OPERATION_ENDS_WITH
  • MailFilterRule.OPERATION_STARTS_WITH

 

  • Value:          Sets the value that will be used for the evaluation process.   
  •  Active:       Sets whether the rule is enabled.                                  

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.MailFilterRule;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);

            long filterId = 2;// Valid filter id 

            MailFilterRule rule = new MailFilterRule();
            rule.setOperation(MailFilterRule.OPERATION_CONTAINS);
            rule.setValue("test");
            rule.setField(MailFilterRule.FIELD_FROM);
            rule.setActive(false);

            ws.mail.createRule(filterId, rule);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

updateRule

Description:

Method Return values Description

updateMailRule(MailFilterRule rule)

void

Update an email account rule.


 Mail account filter parameters:

  • Field: Sets the mail field that will be evaluated by the rule.

Available options are: 

  • MailFilterRule.FIELD_FROM
  • MailFilterRule.FIELD_TO
  • MailFilterRule.FIELD_SUBJECT
  • MailFilterRule.FIELD_CONTENT
  • MailFilterRule.FIELD_ATTACHMENT              
  • Operation:  Set the operation that will be performed during the evaluation process.

Available options are:

  • MailFilterRule.OPERATION_EQUALS
  • MailFilterRule.OPERATION_NOT_EQUALS
  • MailFilterRule.OPERATION_CONTAINS
  • MailFilterRule.OPERATION_ENDS_WITH
  • MailFilterRule.OPERATION_STARTS_WITH
  • Value: Sets the value that will be used for the evaluation process.   
  • Active: Sets whether the rule is enabled.                                  

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.MailFilterRule;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);

            MailFilterRule rule = new MailFilterRule();
            rule.setId(2);
            rule.setOperation(MailFilterRule.OPERATION_EQUALS);
            rule.setValue("test");
            rule.setField(MailFilterRule.FIELD_FROM);
            rule.setActive(false);

            ws.mail.updateRule(rule);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteRule

Description:

Method Return values Description

deleteRule(long ruleId)

void

Delete a rule of an email account.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);

            long ruleId = 1; // Valid rule id
            ws.mail.deleteRule(ruleId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getFilterRules

Description:

Method Return values Description

getFilterRules(long filterId)

List<MailFilterRule>

Retrieve a list of rules for a filter.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.MailFilterRule;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);

            long filterId = 2; // Valid filter id
            for (MailFilterRule mailFilterRule : ws.mail.getFilterRules(filterId)) {
                System.out.println(mailFilterRule);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

forwardEmail

Description:

Method Return values Description

forwardEmail(String uuid, List<String> users, List<String> roles, List<String> mails, String message)

void

Forward an email to a list of users, roles, or external email addresses.

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.List;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);

            String mailUuid = "f123a950-0329-4d62-8328-0ff500fd42db";
            List<String> users = new ArrayList<>();
            users.add("userTest");
            List<String> roles = new ArrayList<>();
            roles.add("ROLE_USER");
            List<String> mails = new ArrayList<>();
            mails.add("test@none.com");

            ws.mail.forwardEmail(mailUuid, users, roles, mails, "Any message");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPdf

Description:

Method Return values Description

getPdf(String uuid)

InputStream

Returns a PDF of the email.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Mail;
import com.openkm.sdk4j.impl.OKMWebservices;
import org.apache.commons.io.IOUtils;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Mail mail = ws.mail.getProperties("4b88cbe9-e73d-45fc-bac0-35e0d6e59e43");
            InputStream is = ws.mail.getPdf(mail.getUuid());
            OutputStream fos = new FileOutputStream("/home/gnujavasergio/okm/" + mail.getSubject() + ".pdf");
            IOUtils.copy(is, fos);
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

saveAsPdf

Description:

Method Return values Description

saveAsPdf(String uuid, String newName, boolean propertyGroups, boolean security)

Document

Save the mail as a PDF in the OpenKM repository.

The value of the uuid parameter should be a Mail UUID.

When the newName parameter value is null, the document will keep the same name.

Additional:

  •  When the propertyGroups parameter is true, the metadata groups of the source are copied to the target.
  • When the security parameter is true, the security of the source is copied to the target.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.bean.Mail;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Mail mail = ws.mail.getProperties("7f6c5c0b-a66b-4782-9595-e14b402a18b0");
            Document docPdf = ws.mail.saveAsPdf(mail.getUuid(), mail.getSubject() + ".pdf", true, true);
            System.out.println("Document pdf: " + docPdf.getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}