Skip to content
Other versions

Loading…

Mail samples

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

Description:

Method Return values Description
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:

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

Description:

Method Return values Description
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());
}
}
}
}

Description:

Method Return values Description
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());
}
}
}
}

Description:

Method Return values Description
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.

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

Description:

Method Return values Description
renameMail(String mailId, String newName) void Renames 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.renameMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "new name");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

Description:

Method Return values Description
moveMail(String mailId, String dstId) void Moves a mail into a folder or record.

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

Description:

Method Return values Description
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.

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

Description:

Method Return values Description
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.

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

Description:

Method Return values Description
getMailChildren(String fldId) List 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());
}
}
}
}

Description:

Method Return values Description
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());
}
}
}
}

Description:

Method Return values Description
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());
}
}
}
}

Description:

Method Return values Description
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());
}
}
}
}

Description:

Method Return values Description
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());
}
}
}
}