Mail samples

Basics

On most methods, you'll see the parameter named "mailId". The value of this parameter can be a valid mail UUID.

Example of fldId:

  • Using UUID -> "50b7a5b9-89d2-430e-bbc9-6a6e01662a71"

Suggested code sample

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.newInstance(host);

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

ws.login(user, password);

Once you are logged with the webservices the session is keep in the webservice Object. Then you can use the other API method

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

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

Methods

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); 
try {
ws.login(user, password); System.Console.WriteLine(ws.mail.getMailProperties("f0064cf3-4776-44c2-868a-f08697a6957e").toString()); } 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); 
try {
ws.login(user, password); ws.mail.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); 
try {
ws.login(user, password); ws.mail.purgeMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

renameMail

Description:

MethodReturn valuesDescription

renameMail(String mailId, String newName)

Mail

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); 
try {
ws.login(user, password); ws.mail.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.

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); 
try {
ws.login(user, password); ws.mail.moveMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "055e4384-7c70-4456-b32b-f5a55a79861f"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

copyMail

Description:

MethodReturn valuesDescription

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

Mail

Copies mail into a folder or record.

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

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); 
try {
ws.login(user, password); ws.mail.copyMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "055e4384-7c70-4456-b32b-f5a55a79861f", "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)

Mail

Copies 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, 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); 
try {
ws.login(user, password); ws.mail.extendedMailCopy("fe51797c-be0b-4076-8f4b-b4fffe8fd2bc", "055e4384-7c70-4456-b32b-f5a55a79861f", 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);
try {
ws.login(user, password); foreach (Mail mail in ws.mail.getMailChildren("055e4384-7c70-4456-b32b-f5a55a79861f")) { 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);
try {
ws.login(user, password); // Return true ws.mail.isValidMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getMailPath

Description:

MethodReturn valuesDescription

getMailPath(String mailId)

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); 
             try {
ws.login(user, password); System.Console.WriteLine(ws.mail.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 in the mail an attachment.

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);
             try {
ws.login(user, password); FileStream fs = new FileStream("E:\\logo.png", FileMode.Open); ws.mail.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); 
             try {
ws.login(user, password);                 ws.mail.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>

Retrieves 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); 
             try {
ws.login(user, password); foreach (Document doc in ws.mail.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, List<String> replyTo, String subject, String body,
List<String> docsId, String uuid)

Mail

Sends a mail message with an attachement.

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

Other parameters:

  • to are a list of mail accounts destination.
  • subject is the mail subject.
  • cc, bcc is a list of mail accounts destination ( optional )
  • docsId is a list of valid document UUID already into OpenKM that will be sent as an 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); 
             try {
ws.login(user, password); 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>();
List<String> replyTo= new List<String>(); docsId.Add("7aa523e0-06cf-4733-b8c8-cc74d8b2716d"); docsId.Add("f123a950-0329-4d62-8328-0ff500fd42db"); ws.mail.sendMailWithAttachments(to, cc, bcc, replyTo, "some subject", "This mail its a test.", docsId, "055e4384-7c70-4456-b32b-f5a55a79861f"); } 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);
try {
ws.login(user, password); FileStream filestream = new FileStream("C:\\Documents\\test.eml", FileMode.Open); Mail mail = ws.mail.importEml("f123a950-0329-4d62-8328-0ff500fd42db", "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);
try {
ws.login(user, password); FileStream filestream = new FileStream("C:\\Documents\\test.msg", FileMode.Open); Mail mail = ws.mail.importMsg("f123a950-0329-4d62-8328-0ff500fd42db", "Test", filestream); System.Console.WriteLine(mail); filestream.Close(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

setMailTitle

Description:

MethodReturn valuesDescription

setMailTitle(String mailId, String title)

Mail

Sets the mail title.

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); 
try {
ws.login(user, password); ws.mail.setMailTitle("68ed7a93-005c-4ec6-ac01-bb151573c775", "new title"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

sendMail

 Description:

MethodReturn valuesDescription

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

Void

Sends 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);
try {
ws.login(user, password); List<String> recipients = new List<string>(); recipients.Add("some@mail.com"); ws.mail.sendMail(recipients, "Testing sending mail from OpenKM", "Test message body."); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

setMailNodeClass

Description:

MethodReturn valuesDescription

setMailNodeClass(String mailId, long ncId)

void

Sets the mail node class.

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); 
try {
ws.login(user, password); ws.mail.setMailNodeClass("68ed7a93-005c-4ec6-ac01-bb151573c775", ncId); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

setMailDescription

Description:

MethodReturn valuesDescription

setMailDescription(String mailId, String description)

void

Sets the mail title.

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); 
try {
ws.login(user, password); ws.mail.setMailDescription("68ed7a93-005c-4ec6-ac01-bb151573c775", "Any description"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getMailContent

Description:

MethodReturn valuesDescription

getMailContent(String mailId)

Stream

Sets the mail title.

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); 
try {
ws.login(user, password);  Stream s = ws.mail.getMailContent("68ed7a93-005c-4ec6-ac01-bb151573c775");
FileStream mailFile = new FileStream("C:\\mailtest.msg", FileMode.OpenOrCreate);
s.CopyTo(mailFile);
s.Close();
mailFile.Close(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getMailThumbnail

Description:

MethodReturn valuesDescription

getMailThumbnail(String mailId, String type)

Stream

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:

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); 
try {
ws.login(user, password); Stream s = ws.mail.getMailThumbnail("68ed7a93-005c-4ec6-ac01-bb151573c775", ThumbnailType.THUMBNAIL_PROPERTIES); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

setMailDispositionStage

Description:

MethodReturn valuesDescription

setMailDispositionStage(String uuid, long stage)

void

Sets the mail disposition stage.

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); 
try {
ws.login(user, password);
long stage = 1;
ws.mail.setMailDispositionStage("f0064cf3-4776-44c2-868a-f08697a6957e", stage); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

createWizardMail

Description:

MethodReturn valuesDescription

createWizardMail(String uuid, String title, FileStream fileStream, String type) 

WizardNode

Create a mail with wizard.

The Wizard node contains the steps what might be followed by the wizard:

  • Metadata groups
  • Keywords
  • Categories

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);

            try
            {
                ws.login(user, password);
                Folder fld = ws.createFolder("f123a950-0329-4d62-8328-0ff500fd42db", "Test");
FileStream filestream = new FileStream("C:\\testing.msg", FileMode.Open, FileAccess.Read);
WizardNode wn = ws.mail.createWizardMail(fld.uuid, "Any title", filestream, Mail.ORIGIN_MSG);
filestream.Close();
System.Console.WriteLine(wn.toString()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getMailsPaginated

Description:

MethodReturn valuesDescription

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

NodeList

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

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

  • The parameter "limit" is used to limit the number of results returned.
  • The parameter "offset" says to skip that many results before the beginning to return results.
  • The parameter "filter" must be the canonical class name of the class which implements the NodeProperties interface.
  • The parameter "orderColumn" can have the following values: uuid, subject, from, sentDate and hasAttachments.
  • The parameter "orderAsc" can be "true" in case of ascending order and "false" otherwise.

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

  • limit=10
  • offset=0

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

  • limit=10
  • offset=10

Example:

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);

            try
            {
                ws.login(user, password);
                MailFilterQuery filter = new MailFilterQuery();
filter.subject = "";
filter.attachments = AttachmentEnum.ALL;
String orderColumn = "subject";
NodeList nodes = ws.mail.getMailsPaginated(0, 10, filter, orderColumn, true);

foreach (Node node in nodes)
{
System.Console.WriteLine(node.toString());
} } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getMailAccounts

Description:

MethodReturn valuesDescription

getMailAccounts()

List<MailAccount>

Retrieves a list of user email accounts.

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); 
            
            try
            {
                ws.login(user, password);
                foreach (MailAccount mail in ws.mail.getMailAccounts())
                {
                    System.Console.WriteLine(mail.toString());
                }
            } 
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            } 
        }
    }
}

getMailMessages

Description:

MethodReturn valuesDescription

getMailMessages(long accountId, long start)

MailServerMessages

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

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); 
            
            try
            {
                ws.login(user, password);
long accoundId = 1;
long start = 1;
MailServerMessages msm = ws.mail.getMailMessages(accoundId, start); System.Console.WriteLine(msm.toString()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

addMailAccount

Description:

MethodReturn valuesDescription

addMailAccount(MailAccount mailAccount)

void

Add an email account.

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

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

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); 
            
            try
            {
                ws.login(user, password);
MailAccount mailAcount = new MailAccount();
mailAcount.mailProtocol = MailAccount.PROTOCOL_IMAPS;
mailAcount.mailUser = "test@none.com";
mailAcount.mailPassword = "123456";
mailAcount.mailHost = "imap.gmail.com";
mailAcount.mailFolder = "OpenKM";
mailAcount.active = true;
mailAcount.recursive = true;
ws.mail.addMailAccount(mailAcount); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

updateMailAccount

Description:

MethodReturn valuesDescription

updateMailAccount(MailAccount mailAccount)

void

Update the main configuration data of an email account.

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); 
            
            try
            {
                ws.login(user, password);
MailAccount mailAcount = new MailAccount();
mailAcount.id = 1;// Valid mail account id;
mailAcount.mailProtocol = MailAccount.PROTOCOL_IMAPS;
mailAcount.mailUser = "test@none.com";
mailAcount.mailPassword = "123456";
mailAcount.mailHost = "imap.gmail.com";
mailAcount.mailFolder = "OpenKM";
mailAcount.active = false;
mailAcount.mailMarkDeleted = false;
mailAcount.recursive = false;
ws.mail.updateMailAccount(mailAcount); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

testMailAccount

Description:

MethodReturn valuesDescription

testMailAccount(MailAccount mailAccount)

void

Verify connectivity of an email account.

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); 
            
            try
            {
                ws.login(user, password);
MailAccount mailAcount = new MailAccount();
mailAcount.mailProtocol = MailAccount.PROTOCOL_IMAPS;
mailAcount.mailUser = "test@none.com";
mailAcount.mailPassword = "123456";
mailAcount.mailHost = "imap.gmail.com";
mailAcount.mailFolder = "OpenKM";
mailAcount.active = true;
mailAcount.recursive = true;

// Test mail account
ws.mail.testMailAccount(mailAcount); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

deleteMailAccount

Description:

MethodReturn valuesDescription

deleteMailAccount(long mailAccountId)

void

Delete an email account.

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); 
            
            try
            {
                ws.login(user, password);
long mailId = 1; //Valid mail id
ws.mail.deleteMailAccount(mailId); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

importMailMessages

Description:

MethodReturn valuesDescription

importMailMessages(long mailAccountId, List<long> messageIds)

void

Import messages of aa specific email account.

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); 
            
            try
            {
                ws.login(user, password);
List<long> messageIds = new List<long>();
messageIds.Add(1);
long mailAccountId = 1; // Valid mail id
ws.mail.importMailMessages(mailAccountId, messageIds); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

createMailFilter

Description:

MethodReturn valuesDescription

createMailFilter(long mailAccountId, MailFilter mailFilter)

void

Add a filter of an email account.

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); 
            
            try
            {
                ws.login(user, password);
Folder fld = ws.createFolder("f123a950-0329-4d62-8328-0ff500fd42db", "FilterFolder");
// Valid mail account id
long mailAccountId = 1;
MailFilter filter = new MailFilter();
filter.order = 0;
filter.grouping = false;
filter.exclusive = true;
filter.active = false;
filter.node = fld.uuid;
ws.mail.createMailFilter(mailAccountId, filter); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

updateMailFilter

Description:

MethodReturn valuesDescription

updateMailFilter(MailFilter mailFilter)

void

Update the filter of an email account.

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); 
            
            try
            {
                ws.login(user, password);
  MailFilter filter = new MailFilter();
filter.id = 1; // Valid filter id
filter.grouping = true;
filter.exclusive = false;
filter.active = true;
ws.mail.updateMailFilter(filter); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

deleteMailFilter

Description:

MethodReturn valuesDescription

deleteMailFilter(long mailFilterId)

void

Delete a filter of an email account.

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); 
            
            try
            {
                ws.login(user, password);                
long filterId = 1; // Valid filter id
ws.mail.deleteMailFilter(filterId); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

createMailRule

Description:

MethodReturn valuesDescription

createMailRule(long filterId, MailFilterRule rule)

void

Create a rule of an email filter.


 Mail account filter parameters:

  • Field:           Sets the mail field that will be evaluated by the rule.
                         Available options are: From, To, Subject and Content
                         - MailFilterRule.FIELD_FROM
                         - MailFilterRule.FIELD_TO
                         - MailFilterRule.FIELD_SUBJECT
                         - MailFilterRule.FIELD_CONTENT
                         - MailFilterRule.FIELD_ATTACHMENT
  • Operation:  Set the operation that will be done for the evaluation process. 
                         Available options are:  Contains and Equal   
                         - 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 rule enabled 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); 
            
            try
            {
                ws.login(user, password);                
MailFilterRule rule = new MailFilterRule();
rule.operation = MailFilterRule.OPERATION_CONTAINS;
rule.value = "test";
rule.field = MailFilterRule.FIELD_FROM;
rule.active = false;
long filterId = 1;// Valid filter id
ws.mail.createMailRule(filterId, rule); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

updateMailRule

Description:

MethodReturn valuesDescription

updateMailRule(MailFilterRule rule)

void

Update a rule of an email coount.


 Mail account filter parameters:

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

Available options are: 

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

  • Operation:  Set the operation that will be done 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 rule enabled 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); 
            
            try
            {
                ws.login(user, password);                
List<MailFilterRule> rules = ws.getMailFilterRules(filter.id);
if (rules != null && rules.Count > 0)
{
// Update rule
MailFilterRule rule = new MailFilterRule();
rule.id = rules[0].id;
rule.operation = MailFilterRule.OPERATION_EQUALS;
rule.value = "Any";
rule.field = MailFilterRule.FIELD_SUBJECT;
rule.active = true;
ws.mail.updateMailRule(rule);
} } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

deleteMailRule

Description:

MethodReturn valuesDescription

deleteMailRule(long ruleId)

void

Delete a rule of an email account.

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); 
            
            try
            {
                ws.login(user, password);                
long ruleId = 1; // Valid rule id
ws.mail.deleteMailRule(ruleId); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getMailFilterRules

Description:

MethodReturn valuesDescription

getMailFilterRules(long filterId)

List<MailFilterRule>

Retrieve a list of all the associated rules of type filter.

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); 
            
            try
            {
                ws.login(user, password);
  long filterId = 1; // Valid filter id
foreach (MailFilterRule mfrule in ws.mail.getMailFilterRules(filterId))
{
System.Console.WriteLine(mfrule.toString());
} } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

forwardEmail

Description:

MethodReturn valuesDescription

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

void

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

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); 
            
            try
            {
                ws.login(user, password);
  string mailUuid = "f123a950-0329-4d62-8328-0ff500fd42db";
List<string> users = new List<string>();
users.Add("userTest");
List<string> roles = new List<string>();
roles.Add("ROLE_USER");
List<string> mails = new List<string>();
mails.Add("test@none.com");
ws.mail.forwardEmail(mailUuid, users, roles, mails, "Any message"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }