Mail samples

Basics

On most 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 -> "50b7a5b9-89d2-430e-bbc9-6a6e01662a71";
  • 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 )

Mails account 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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
using System.Net;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice 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.path = mailPath;
                    // Other format for mail "some name <no_reply@openkm.com>" mail.from = "<no_reply@openkm.com>"; String[] to = new String[] { "anonymous@gmail.com" }; mail.to = to;
                     // You should set real dates mail.sentDate = DateTime.Now; mail.receivedDate = DateTime.Now; mail.content = "some content"; mail.mimeType = Mail.MIME_TEXT; mail.subject = subject; mail.origin = Mail.ORIGIN_API;
// Get only as an approximation of real size for these sample mail.size = mail.toString().Length; ws.createMail(mail); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } private static String escape(String name) { String ret = cleanup(name); // Fix XSS issues ret = WebUtility.HtmlEncode(name); return ret; } private static String cleanup(String name) { String ret = name.Replace("/", ""); ret = ret.Replace("*", ""); ret = ret.Replace("\\s+", " ").Trim(); return ret; } } }

getMailProperties

Description:

MethodReturn valuesDescription

getMailProperties(String mailId)

Mail

Returns the mail properties.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try { System.Console.WriteLine(ws.getMailProperties("50b7a5b9-89d2-430e-bbc9-6a6e01662a71")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

deleteMail

Description:

MethodReturn valuesDescription

deleteMail(String mailId)

void

Delete a mail.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try { ws.deleteMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

purgeMail

Description:

MethodReturn valuesDescription

purgeMail(String mailId)

void

Folder is definitely removed from repository.

Usually you will purge mails into /okm:trash/userId - the personal trash user locations - but is possible to directly purge any mail from the whole repository.

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

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try { ws.purgeMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try { ws.renameMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "new name"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try { ws.moveMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "/okm:root/tmp"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

copyMail

Description:

MethodReturn valuesDescription

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

void

Copy 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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try { ws.copyMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "/okm:root/tmp", "new_name"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

extendedMailCopy

Description:

MethodReturn valuesDescription

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

void

Copies 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 copyed.

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 the wiki parameter is true the original values of the wiki will be copied.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try { ws.extendedMailCopy("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "/okm:root/tmp", true, true, true, true, true); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getMailChildren

Description:

MethodReturn valuesDescription

 getMailChildren(String fldId)

List<Mail>

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

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try { foreach (Mail mail in ws.getMailChildren("/okm:root/")) { System.Console.WriteLine(mail); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

isValidMail

Description:

MethodReturn valuesDescription

isValidMail(String mailId)

Boolean

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

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try { // Return false ws.isValidMail("/okm:root/logo.png");
// Return true ws.isValidMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getMailPath

Description:

MethodReturn valuesDescription

getMailPath(String uuid)

String

Converts mail UUID to folder path.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getMailPath("50b7a5b9-89d2-430e-bbc9-6a6e01662a71")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

createAttachment

Description:

MethodReturn valuesDescription

createAttachment(String mailId, String docName, InputStream is)

Document

Stores an attachment into the mail .

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
using System.IO;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { FileStream fs = new FileStream("E:\\logo.png", FileMode.Open); ws.createAttachment("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "log.png", fs); fs.Dispose(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

deleteAttachment

Description:

MethodReturn valuesDescription

deleteAttachment(String mailId, String docId)

void

Deletes a mail attachment.

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

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try {                 ws.deleteAttachment("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "e339f14b-4d3a-489c-91d3-05e4575709d2"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getAttachments

Description:

MethodReturn valuesDescription

getAttachments(String mailId)

List<Document>

Retrieve a list of all documents attachment of a mail.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { foreach (Document doc in ws.getAttachments("50b7a5b9-89d2-430e-bbc9-6a6e01662a71")) { System.Console.WriteLine(doc); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

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 into the repository after be sended.

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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { List<String> to = new List<String>(); to.Add("destination@mail.com"); List<String> cc = new List<String>(); List<String> bcc = new List<String>(); List<String> docsId = new List<String>(); docsId.Add("7aa523e0-06cf-4733-b8c8-cc74d8b2716d"); docsId.Add("/okm:root/logo.png"); ws.sendMailWithAttachments(to, cc, bcc, "some subject", "E:\\test.txt", docsId, "/okm:root/tmp"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }