Skip to content
Other versions

Loading…

Mail samples

On most methods, you’ll see the 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
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, username, password);
try
{
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());
}
}
}
}

Description:

Method Return values Description
deleteAttachment(String mailId, String docId) void Deletes a mail attachment.

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.deleteAttachment("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "e339f14b-4d3a-489c-91d3-05e4575709d2");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

Description:

Method Return values Description
getAttachments(String mailId) List 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, username, password);
try
{
foreach (Document doc in ws.getAttachments("50b7a5b9-89d2-430e-bbc9-6a6e01662a71"))
{
System.Console.WriteLine(doc);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

Description:

Method Return values Description
sendMailWithAttachments(String from, List to, List cc, List bcc, String subject, String body, List docsId, String dstId) void 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, username, password);
try
{ String from ="Test@openkm.com";
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>();
docsId.Add("7aa523e0-06cf-4733-b8c8-cc74d8b2716d");
docsId.Add("/okm:root/logo.png");
ws.sendMailWithAttachments(from, to, cc, bcc, "some subject", "E:\\test.txt", docsId, "/okm:root/tmp");
}
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());
}
}
}
}

Description:

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

 Description:

Method Return values Description
sendMail(List 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, username, password);
try
{
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());
}
}
}
}