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"
Methods
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);
try
{
ws.login(user, password);
System.Console.WriteLine(ws.getMailProperties("f0064cf3-4776-44c2-868a-f08697a6957e").toString());
}
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);
try
{
ws.login(user, password);
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);
try
{
ws.login(user, password);
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) |
|
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.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. |
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.moveMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "055e4384-7c70-4456-b32b-f5a55a79861f");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
copyMail
Description:
Method | Return values | Description |
---|---|---|
public void copyMail(String mailId, String dstId, String newName) |
|
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.copyMail("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "055e4384-7c70-4456-b32b-f5a55a79861f", "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, |
|
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:
|
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.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:
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);
try
{
ws.login(user, password);
foreach (Mail mail in ws.getMailChildren("055e4384-7c70-4456-b32b-f5a55a79861f"))
{
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);
try
{
ws.login(user, password);
// 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 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.getMailPath("50b7a5b9-89d2-430e-bbc9-6a6e01662a71"));
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
createAttachment
Description:
Method | Return values | Description |
---|---|---|
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.createAttachment("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "log.png", fs);
fs.Dispose();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
deleteAttachment
Description:
Method | Return values | Description |
---|---|---|
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.deleteAttachment("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "e339f14b-4d3a-489c-91d3-05e4575709d2");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getAttachments
Description:
Method | Return values | Description |
---|---|---|
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.getAttachments("50b7a5b9-89d2-430e-bbc9-6a6e01662a71"))
{
System.Console.WriteLine(doc);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
sendMailWithAttachments
Description:
Method | Return values | Description |
---|---|---|
sendMailWithAttachments(List<String> to, List<String> cc, List<String> bcc, List<String> replyTo, String subject, String body, |
|
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:
|
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.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:
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);
try
{
ws.login(user, password);
FileStream filestream = new FileStream("C:\\Documents\\test.eml", FileMode.Open);
Mail mail = ws.importEml("f123a950-0329-4d62-8328-0ff500fd42db", "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);
try
{
ws.login(user, password);
FileStream filestream = new FileStream("C:\\Documents\\test.msg", FileMode.Open);
Mail mail = ws.importMsg("f123a950-0329-4d62-8328-0ff500fd42db", "Test", filestream);
System.Console.WriteLine(mail);
filestream.Close();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
setMailTitle
Description:
Method | Return values | Description |
---|---|---|
setMailTitle(String mailId, String title) |
|
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.setMailTitle("68ed7a93-005c-4ec6-ac01-bb151573c775", "new title");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
sendMail
Description:
Method | Return values | Description |
---|---|---|
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.sendMail(recipients, "Testing sending mail from OpenKM", "Test message body.");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
setMailNodeClass
Description:
Method | Return values | Description |
---|---|---|
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.setMailNodeClass("68ed7a93-005c-4ec6-ac01-bb151573c775", ncId);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
setMailDescription
Description:
Method | Return values | Description |
---|---|---|
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.setMailDescription("68ed7a93-005c-4ec6-ac01-bb151573c775", "Any description");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getMailContent
Description:
Method | Return values | Description |
---|---|---|
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.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:
Method | Return values | Description |
---|---|---|
getMailThumbnail(String mailId, String type) |
Stream |
Returns thumbnail image data. |
Available types:
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.getMailThumbnail("68ed7a93-005c-4ec6-ac01-bb151573c775", ThumbnailType.THUMBNAIL_PROPERTIES);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}