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 return as a result an object Mail.

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

Other mandatory variables:

  • size ( mail size in bytes ).
  • from ( mail from the 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 of 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

Deletes 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 it will only be able to be restored from a previously repository backup. The purge action removes 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

Renames a mail.

From OpenKM frontend UI the subject is used to show the mail name at file browser table. That means the 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

Moves a 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

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

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, String newName)

void

Copies mail 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 property groups 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.
  • When newName is set the mail name is renamed.

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("fe51797c-be0b-4076-8f4b-b4fffe8fd2bc", "/okm:root/tmp", true, true, true, true, true, null);
            } 
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            } 
        }
    }
}

getMailChildren

Description:

MethodReturn valuesDescription

 getMailChildren(String fldId)

List<Mail>

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

importEml

Description:

MethodReturn valuesDescription

importEml(String dstId, String title, FileStream fs)

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 indicates where the mail will be stored in the repository after is sent.

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 filestream = new FileStream("C:\\Documents\\test.eml", FileMode.Open);
                Mail mail = ws.importEml("/okm:root/test", "Test", filestream);
                System.Console.WriteLine(mail);
                filestream.Close();
            } 
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            } 
        }
    }
}

importMsg

Description:

MethodReturn valuesDescription

importMsg(String dstId, String title, FileStream fs)

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 indicates where the mail will be stored in the repository after is sent.

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 filestream = new FileStream("C:\\Documents\\test.msg", FileMode.Open);
                Mail mail = ws.importMsg("/okm:root/test", "Test", filestream);
                System.Console.WriteLine(mail);
                filestream.Close();
            } 
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            } 
        }
    }
}