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:
Method | Return values | Description |
---|---|---|
createMail(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:
Mails account allowed formats:
Mail path allowed is: MSGID + "-" + sanitized(subject). MIME types of values:
Origin values:
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:
Method | Return values | Description |
---|---|---|
getMailProperties(String mailId) |
|
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:
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());
}
}
}
}
purgeMail
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. 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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
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:
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. 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:
Method | Return values | Description |
---|---|---|
extendedMailCopy(String mailId, String dstId, boolean categories, boolean keywords, boolean propertyGroups, boolean notes, |
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:
|
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:
Method | Return values | Description |
---|---|---|
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:
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());
}
}
}
}
getMailPath
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());
}
}
}
}
importEml
Description:
Method | Return values | Description |
---|---|---|
importEml(String dstId, String title, FileStream fs) |
|
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:
Method | Return values | Description |
---|---|---|
importMsg(String dstId, String title, FileStream fs) |
|
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());
}
}
}
}