Mail samples

Basics

Example of UUID:

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

Suggested code sample

First, you must create the web service object:

OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

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

ws.login(user, password);

Once you are logged in to the web services, the session is kept in the web service Object. Then you can use the other API methods

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

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

Methods

getMailProperties

Description:

Method Return values Description

getMailProperties(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.getMailProperties("05d9b8e3-f9c1-4ace-9007-afd775dbbced"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteMail

Description:

Method Return values Description

deleteMail(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.deleteMail("05d9b8e3-f9c1-4ace-9007-afd775dbbced");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

purgeMail

Description:

Method Return values Description

purgeMail(String uuid)

void

Mail is permanently removed from the repository.

Usually, you will purge mails into /okm:trash/userId - the personal trash user locations - but it is possible to directly purge any mail from the 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.purgeMail("05d9b8e3-f9c1-4ace-9007-afd775dbbced");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

renameMail

Description:

Method Return values Description

renameMail(String uuid, String newName)

void

Renames a mail.

In the OpenKM frontend UI, the subject is used to show 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.renameMail("e3831cc4-30f0-419a-8fbf-a3418472ada5", "new name");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

moveMail

Description:

Method Return values Description

moveMail(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.moveMail("e3831cc4-30f0-419a-8fbf-a3418472ada5", "ada67d44-b081-4b23-bdc1-74181cafbc5d");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

copyMail

Description:

Method Return values Description

public void copyMail(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 "extendedMailCopy" 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.copyMail("e3831cc4-30f0-419a-8fbf-a3418472ada5", "ada67d44-b081-4b23-bdc1-74181cafbc5d", "new_name");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

extendedMailCopy

Description:

Method Return values Description

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

Mail

Copy 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. of the folder 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 settings will be copied.
  • When newName is set, the mail name is renamed.

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.extendedMailCopy("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();
        }
    }
}

getMailChildren

Description:

Method Return values Description

 getMailChildren(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.getMailChildren("ada67d44-b081-4b23-bdc1-74181cafbc5d")) {
                System.out.println(mail);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

isValidMail

Description:

Method Return values Description

isValidMail(String uuid)

Boolean

Returns a boolean that indicates whether the node is 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);
            // Return false
            System.out.println(ws.mail.isValidMail("ada67d44-b081-4b23-bdc1-74181cafbc5d"));

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

getMailPath

Description:

Method Return values Description

getMailPath(String uuid)

String

Converts a mail UUID to a 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.getMailPath("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 the 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 values 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 values 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 values 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 values 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();
        }
    }
}

setMailTitle

Description:

Method Return values Description

setMailTitle(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.setMailTitle("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();
        }
    }
}

setMailDescription

Description:

Method Return values Description

setMailDescription(String uuid, String description)

void

Sets 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.setMailDescription("b405a504-d8cb-4166-ac51-22f68acee8c5", "some description");
            Mail mail = ws.mail.getMailProperties("b405a504-d8cb-4166-ac51-22f68acee8c5");
            System.out.println("Description: " + mail.getDescription());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getMailContent

Description:

Method Return values Description

getMailContent(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.getMailContent("b405a504-d8cb-4166-ac51-22f68acee8c5");
            IOUtils.copy(is, fos);
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createWizardMail

Description:

Method Return values Description

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

WizardNode

Create a new document with a wizard.

The parameters uuid should be any 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.createWizardMail("4c195453-246b-4ce9-86ba-b84e68d1f284", "test title", is, Mail.ORIGIN_EML);
            System.out.print(wn);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getMailThumbnail

Description:

Method Return values Description

getMailThumbnail(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();
        }
    }
}

getMailAccounts

Description:

Method Return values Description

getMailAccounts()

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.getMailAccounts()) {
                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 in 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();
        }
    }
}

addMailAccount

Description:

Method Return values Description

addMailAccount(MailAccount mailAccount)

void

Add 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.addMailAccount(mailAcount);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

updateMailAccount

Description:

Method Return values Description

updateMailAccount(MailAccount mailAccount)

void

Update 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.updateMailAccount(mailAcount);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

testMailAccount

Description:

Method Return values Description

testMailAccount(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.testMailAccount(mailAcount);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteMailAccount

Description:

Method Return values Description

deleteMailAccount(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.deleteMailAccount(mailAccountId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

importMailMessages

Description:

Method Return values Description

importMailMessages(long mailAccountId, List<Long> messageIds)

void

Imports email account messages.

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.getMailMessages(mailAccountId, start);
            for (ExternalMail mail : msg.getServerMails()) {
                messageIds.add(mail.getUid());
            }

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

createMailFilter

Description:

Method Return values Description

createMailFilter(long mailAccountId, MailFilter mailFilter)

void

Adds 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);
            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.createMailFilter(mailAccountId, filter);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

updateMailFilter

Description:

Method Return values Description

updateMailFilter(MailFilter mailFilter)

void

Updates the 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.updateMailFilter(filter);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteMailFilter

Description:

Method Return values Description

deleteMailFilter(long mailFilterId)

void

Deletes the 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.deleteMailFilter(filterId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createMailRule

Description:

Method Return values Description

createMailRule(long filterId, MailFilterRule rule)

void

Creates 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:  Sets the operation that will be used for 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 or not.                                  

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.createMailRule(filterId, rule);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

updateMailRule

Description:

Method Return values Description

updateMailRule(MailFilterRule rule)

void

Update 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:  Sets the operation that will be used for 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 or not.                                  

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.updateMailRule(rule);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteMailRule

Description:

Method Return values Description

deleteMailRule(long ruleId)

void

Deletes a rule from 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.deleteMailRule(ruleId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getMailFilterRules

Description:

Method Return values Description

getMailFilterRules(long filterId)

List<MailFilterRule>

Retrieves 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.getMailFilterRules(filterId)) {
                System.out.println(mailFilterRule);
            }
        } 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.getMailProperties("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();
        }
    }
}