Mail samples

Basics

On almost methods you'll see parameter named "mailId". The value of this parameter can be a valid mail UUID or path.

Example of fldId:

  • Using UUID -> "064ff51a-b815-4f48-a096-b4946876784f";
  • Using path -> "/okm:root/2937b81d-0b10-4dd0-a426-9acbd80be1c9-some subject"

Methods

createMail

Description:

MethodReturn valuesDescription

createMail(Mail mail)

Mail

Creates a new mail and returns as a result an object Mail.

The variable path into the parameter mail, must be initializated. It indicates the folder path into OpenKM.

Other mandatory variables:

  • size ( mail size in bytes ).
  • from ( mail from account ).
  • reply, to, cc, bcc ( mail accounts are optional ).
  • sendDate ( date when mail was sent ).
  • receivedDate ( date when was received ).
  • subject ( mail subject ).
  • content ( the mail content ).
  • mimeType ( HTML or text mime type ).
  • headers ( the mail headers are optional).
  • raw ( the mail raw are optional).
  • origin ( msg, eml, api, pop3, imap origin )
  • title ( mail title )

Mai accounts allowed formats:

  • "\"John King\" <jking@mail.com>"
  • "<jking@mail.com>"

Mail path allowed is:

MSGID + "-" + sanitized(subject).

MIME types values:

  • Mail.MIME_TEXT for text mail format.
  • Mail.MIME_HTML for html mail format.

Origin values:

  • Mail.ORIGIN_MSG for .msg mail format.
  • Mail.ORIGIN_EML for .eml mail format.
  • Mail.ORIGIN_API for mail format created from API.
  • Mail.ORIGIN_POP3 for mail imported from pop3 account.
  • Mail.ORIGIN_IMAP for mail imported from imap account.

The other variables of Mail ( mail ) will not take any effect on mail creation.

Example:

package com.openkm;

import java.util.Arrays;
import java.util.Calendar;

import org.owasp.encoder.Encode;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { Mail mail = new Mail();
             // Mail path = msgId + escaped(subject) String msgId = "2937b81d-0b10-4dd0-a426-9acbd80be1c9"; String subject = "some subject"; String mailPath = "/okm:root/"+ msgId + "-" + escape(subject); mail.setPath(mailPath);
            // Other format for mail "some name <no_reply@openkm.com>" mail.setFrom("<no_reply@openkm.com>"); mail.setTo((String[])Arrays.asList("anonymous@gmail.com").toArray());
            // You should set real dates mail.setSentDate(Calendar.getInstance()); mail.setReceivedDate(Calendar.getInstance()); mail.setContent("some content"); mail.setMimeType(Mail.MIME_TEXT); mail.setSubject(subject); mail.setOrigin(Mail.ORIGIN_API);
            // Get only as an approximation of real size for these sample mail.setSize(mail.toString().getBytes("UTF-8").length); ws.createMail(mail); } catch (Exception e) { e.printStackTrace(); } } private static String escape(String name) {         String ret = cleanup(name);                  // Fix XSS issues         ret = Encode.forHtml(ret);                  return ret;     } private static String cleanup(String name) {         String ret = name.replace("/", "");         ret = ret.replace("*", "");         ret = ret.replaceAll("\\s+", " ").trim();         return ret;     } }

getMailProperties

Description:

MethodReturn valuesDescription

getMailProperties(String mailId)

Mail

Returns the mail properties.

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { System.out.println(ws.getMailProperties("064ff51a-b815-4f48-a096-b4946876784f")); } catch (Exception e) { e.printStackTrace(); } } }

deleteMail

Description:

MethodReturn valuesDescription

deleteMail(String mailId)

void

Deletes a mail.

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.deleteMail("064ff51a-b815-4f48-a096-b4946876784f"); } catch (Exception e) { e.printStackTrace(); } } }

purgeMail

Description:

MethodReturn valuesDescription

purgeMail(String mailId)

void

Mail is definitely removed from 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 whole repository.

When a mail is purged it will  only be able to be restored from a previously repository backup. The purge action removes the mail definitely from the repository.

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.purgeMail("064ff51a-b815-4f48-a096-b4946876784f"); } catch (Exception e) { e.printStackTrace(); } } }

renameMail

Description:

MethodReturn valuesDescription

renameMail(String mailId, String newName)

void

Rename a mail.

From OpenKM frontend UI the subject is used to show the mail name at file browser table. That means this change will take effect internally on mail path, but will not be appreciated from default UI.

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.renameMail("064ff51a-b815-4f48-a096-b4946876784f","new name"); } catch (Exception e) { e.printStackTrace(); } } }

moveMail

Description:

MethodReturn valuesDescription

moveMail(String mailId, String dstId)

void

Move mail into a folder or record.

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

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.moveMail("064ff51a-b815-4f48-a096-b4946876784f","/okm:root/tmp"); } catch (Exception e) { e.printStackTrace(); } } }

copyMail

Description:

MethodReturn valuesDescription

public void copyMail(String mailId, String dstId, String newName)

void

Copies mail into a folder or record.

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

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

Only the security grants are copied to 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.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.copyMail("064ff51a-b815-4f48-a096-b4946876784f","/okm:root/temp","new_name"); } catch (Exception e) { e.printStackTrace(); } } }

extendedMailCopy

Description:

MethodReturn valuesDescription

extendedMailCopy(String mailId, String dstId, boolean categories, boolean keywords, boolean propertyGroups, boolean notes,
            boolean wiki, String newName)

void

Copy mail width with associated data into a folder or record.

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

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

Additional:

  • When the category 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 wiki parameter is true the original values of the wiki will be copied.
  • When newName is set the mail name is renamed.

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.extendedMailCopy("064ff51a-b815-4f48-a096-b4946876784f", "/okm:root/tmp", true, true, true, true, true, null); } catch (Exception e) { e.printStackTrace(); } } }

getMailChildren

Description:

MethodReturn valuesDescription

 getMailChildren(String fldId)

List<Mail>

Returns a list of all mails which their parent is fldId.

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username =  "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             for (Mail mail : ws.getMailChildren("/okm:root")) {                 System.out.println(mail);             } } catch (Exception e) { e.printStackTrace(); } } }

isValidMail

Description:

MethodReturn valuesDescription

isValidMail(String mailId)

Boolean

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

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { // Return false ws.isValidMail("/okm:root/logo.png");
             // Return true ws.isValidMail("064ff51a-b815-4f48-a096-b4946876784f"); } catch (Exception e) { e.printStackTrace(); } } }

getMailPath

Description:

MethodReturn valuesDescription

getMailPath(String uuid)

String

Converts mail UUID to mail path.

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { System.out.println(ws.getMailPath("064ff51a-b815-4f48-a096-b4946876784f")); } catch (Exception e) { e.printStackTrace(); } } }

createAttachment

Description:

MethodReturn valuesDescription

createAttachment(String mailId, String docName, InputStream is)

Document

Adds an attachement 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.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             InputStream is = new FileInputStream("/home/files/logo.png");             ws.createAttachment("064ff51a-b815-4f48-a096-b4946876784f", "log.png", is);             IOUtils.closeQuietly(is); } catch (Exception e) { e.printStackTrace(); } } }

deleteAttachment

Description:

MethodReturn valuesDescription

deleteAttachment(String mailId, String docId)

void

Delete a mail attachment.

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

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try { ws.deleteAttachment("064ff51a-b815-4f48-a096-b4946876784f", "f123a950-0329-4d62-8328-0ff500fd42db"); } catch (Exception e) { e.printStackTrace(); } } }

getAttachments

Description:

MethodReturn valuesDescription

getAttachments(String mailId)

List<Document>

Retrieves a list of all the  attachment documents of the mails.

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             for (Document doc : ws.getAttachments("064ff51a-b815-4f48-a096-b4946876784f")) {                 System.out.println(doc);             } } catch (Exception e) { e.printStackTrace(); } } }

sendMailWithAttachments

Description:

MethodReturn valuesDescription

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

void

Send mail message with attachement.

The values of the dstId parameter should be a folder or record UUID or path. The dstId parameter indicate where the mail will be stored in the repository after is sent.

Other parameters:

  • to are a list of mail accounts destination.
  • subject is the mail subject.
  • cc, bcc are a list of mail accounts destination ( optional )
  • docsId are a list of valid document UUID already into OpenKM that will be send as attachment into mail ( optional ).

Example:

package com.openkm;

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

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             List<String> to = Arrays.asList("destination@mail.com");             List<String> cc = new ArrayList<>();             List<String> bcc = new ArrayList<>();             List<String> docsId = Arrays.asList("f123a950-0329-4d62-8328-0ff500fd42db","/ok m:root/logo.png");             ws.sendMailWithAttachments(to, cc, bcc, "some subject", "some body", docsId, "/okm:root/tmp"); } catch (Exception e) { e.printStackTrace(); } } }

importEml

Description:

MethodReturn valuesDescription

importEml(String dstId, String title, InputStream is)

Mail

Import a mail in EML format.

The values of the dstId parameter should be a folder or record UUID or path. The dstId parameter indicate where the mail will be stored in the repository after is imported.

Example:

package com.openkm;

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

import org.apache.commons.io.IOUtils;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username =  "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);

        try {
            InputStream is = new FileInputStream("/home/files/test.eml");
            Mail mail = ws.importEml("d88cff0d-903a-4c5a-82ea-8e6dbd100d65", "some title", is);
            System.out.println(mail);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }   
}

importMsg

Description:

MethodReturn valuesDescription

importMsg(String dstId, String title, InputStream is)

Mail

Import a mail in MSG format.

The values of the dstId parameter should be a folder or record UUID or path. The dstId parameter indicate where the mail will be stored in the repository after is sent.

Example:

package com.openkm;

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

import org.apache.commons.io.IOUtils;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username =  "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);

        try {
            InputStream is = new FileInputStream("/home/files/test.msg");
            Mail mail = ws.importMsg("d88cff0d-903a-4c5a-82ea-8e6dbd100d65", "some title", is);
            System.out.println(mail);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }   
}

setMailTitle

Description:

MethodReturn valuesDescription

setMailTitle(String mailId, String title)

void

Sets the mail title.

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);        
        try {
            ws.setMailTitle("68ed7a93-005c-4ec6-ac01-bb151573c775", "new title");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

sendMail

Description:

MethodReturn valuesDescription

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.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);        
        try {
            StringBuffer body = new StringBuffer();
            body.append("Test message body.");
            List<String> recipients = new ArrayList<>();
            recipients.add("some@mail.com");
            ws.sendMail(recipients, "Testing sending mail from OpenKM", body.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}