Mail samples
Basics
Section titled “Basics”On most methods, you’ll see the parameter named “mailId”. The value of this parameter can be a valid mail UUID.
Suggested code sample
Section titled “Suggested code sample”First, you must create the webservice object:
OKMWebservices ws = OKMWebservicesFactory.newInstance(host);Then you should log in using the “login” method. You can access the “login” method from the webservice object “ws” as shown below:
ws.login(user, password);At this point you can use all the Mail methods from the “mail” class as shown below:
ws.mail.getProperties("05d9b8e3-f9c1-4ace-9007-afd775dbbced")Methods
Section titled “Methods”getProperties
Section titled “getProperties”Description:
| Method | Return values | Description |
|---|---|---|
| getProperties(String uuid) | 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.getProperties("f0064cf3-4776-44c2-868a-f08697a6957e").toString()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}delete
Section titled “delete”Description:
| Method | Return values | Description |
|---|---|---|
| delete(String uuid) | 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.delete("50b7a5b9-89d2-430e-bbc9-6a6e01662a71"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}Description:
| Method | Return values | Description |
|---|---|---|
| purge(String uuid) | void | Folder is permanently removed from the repository. |
Usually, you will purge mails into /okm:trash/userId - the personal trash user location - but it is possible to directly purge any mail 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.purge("50b7a5b9-89d2-430e-bbc9-6a6e01662a71"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}rename
Section titled “rename”Description:
| Method | Return values | Description |
|---|---|---|
| rename(String uuid, 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);
try { ws.login(user, password); ws.mail.rename("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "new name"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}Description:
| Method | Return values | Description |
|---|---|---|
| move(String uuid, 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.move("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "055e4384-7c70-4456-b32b-f5a55a79861f"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}Description:
| Method | Return values | Description |
|---|---|---|
| public void copy(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 the newName parameter value is null, the 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);
try { ws.login(user, password); ws.mail.copy("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "055e4384-7c70-4456-b32b-f5a55a79861f", "new_name"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}extendedCopy
Section titled “extendedCopy”Description:
| Method | Return values | Description |
|---|---|---|
| extendedCopy(String mailId, String dstId, bool categories, bool keywords, bool propertyGroups, bool notes, bool security, String newName) | Copies mail with associated data 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.extendedCopy("fe51797c-be0b-4076-8f4b-b4fffe8fd2bc", "055e4384-7c70-4456-b32b-f5a55a79861f", true, true, true, true, true, null); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}getChildren
Section titled “getChildren”Description:
| Method | Return values | Description |
|---|---|---|
| getChildren(String fldId) | List |
Returns a list of all mails whose 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.getChildren("055e4384-7c70-4456-b32b-f5a55a79861f")) { System.Console.WriteLine(mail); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}isValid
Section titled “isValid”Description:
| Method | Return values | Description |
|---|---|---|
| isValid(String mailId) | Boolean | Returns a boolean that indicates whether the node is 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); // Return true ws.mail.isValid("50b7a5b9-89d2-430e-bbc9-6a6e01662a71"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}getPath
Section titled “getPath”Description:
| Method | Return values | Description |
|---|---|---|
| getPath(String mailId) | String | Converts a mail UUID to a 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.getPath("50b7a5b9-89d2-430e-bbc9-6a6e01662a71")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}createAttachment
Section titled “createAttachment”Description:
| Method | Return values | Description |
|---|---|---|
| createAttachment(String mailId, String docName, InputStream is) | Document | Stores an attachment in the mail. |
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
Section titled “deleteAttachment”Description:
| Method | Return values | Description |
|---|---|---|
| deleteAttachment(String mailId, String docId) | void | Deletes a mail attachment. |
The docId parameter value 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
Section titled “getAttachments”Description:
| Method | Return values | Description |
|---|---|---|
| getAttachments(String mailId) | List |
Retrieves a list of all document attachments 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
Section titled “sendMailWithAttachments”Description:
| Method | Return values | Description |
|---|---|---|
| sendMailWithAttachments(String from, List String body, List |
Sends a mail message with an attachment. |
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 being sent.
Other parameters:
- to is a list of destination email addresses.
- subject is the mail subject.
- cc and bcc are lists of destination email addresses (optional)
- docsId is a list of valid document UUIDs already in OpenKM that will be sent as attachments in the 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); string from = "test@none.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>(); List<String> replyTo= new List<String>(); docsId.Add("7aa523e0-06cf-4733-b8c8-cc74d8b2716d"); docsId.Add("f123a950-0329-4d62-8328-0ff500fd42db"); ws.mail.sendMailWithAttachments(from, 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
Section titled “importEml”Description:
| Method | Return values | Description |
|---|---|---|
| importEml(String dstId, String title, FileStream fs) | Imports 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 being 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
Section titled “importMsg”Description:
| Method | Return values | Description |
|---|---|---|
| importMsg(String dstId, String title, FileStream fs) | Imports 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 being 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()); } } }}setTitle
Section titled “setTitle”Description:
| Method | Return values | Description |
|---|---|---|
| setTitle(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.mail.setTitle("68ed7a93-005c-4ec6-ac01-bb151573c775", "new title"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}sendMail
Section titled “sendMail”Description:
| Method | Return values | Description |
|---|---|---|
| sendMail(String to, 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); ws.mail.sendMail("some@none.com", "Testing sending mail", "Test message body."); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}sendMail
Section titled “sendMail”Description:
| Method | Return values | Description |
|---|---|---|
| sendMail(List |
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> to = new List<string>(); to.Add("some@mail.com"); ws.mail.sendMail(to, "Testing sending mail from OpenKM", "Test message body."); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}sendMail
Section titled “sendMail”Description:
| Method | Return values | Description |
|---|---|---|
| sendMail(String from, List |
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); string from = "test@mome.com" List<String> to = new List<string>(); to.Add("some@mail.com"); ws.mail.sendMail(from, to, "Testing sending mail from OpenKM", "Test message body."); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}setNodeClass
Section titled “setNodeClass”Description:
| Method | Return values | Description |
|---|---|---|
| setNodeClass(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.setNodeClass("68ed7a93-005c-4ec6-ac01-bb151573c775", ncId); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}setDescription
Section titled “setDescription”Description:
| Method | Return values | Description |
|---|---|---|
| setDescription(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.setDescription("68ed7a93-005c-4ec6-ac01-bb151573c775", "Any description"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}getContent
Section titled “getContent”Description:
| Method | Return values | Description |
|---|---|---|
| getContent(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.getContent("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()); } } }}getThumbnail
Section titled “getThumbnail”Description:
| Method | Return values | Description |
|---|---|---|
| getThumbnail(String mailId, ThumbnailType 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 )
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.getThumbnail("68ed7a93-005c-4ec6-ac01-bb151573c775", ThumbnailType.THUMBNAIL_PROPERTIES); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}setDispositionStage
Section titled “setDispositionStage”Description:
| Method | Return values | Description |
|---|---|---|
| setDispositionStage(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.setDispositionStage("f0064cf3-4776-44c2-868a-f08697a6957e", stage); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}createWizard
Section titled “createWizard”Description:
| Method | Return values | Description |
|---|---|---|
| createWizard(String uuid, String title, FileStream fileStream, String type) | WizardNode | Creates a mail with a wizard. |
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.createWizard(fld.uuid, "Any title", filestream, Mail.ORIGIN_MSG); filestream.Close(); System.Console.WriteLine(wn.toString()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}getMailsPaginated
Section titled “getMailsPaginated”Description:
| Method | Return values | Description |
|---|---|---|
| getMailsPaginated(String context, int offset, int limit, MailFilterQuery filter, String orderColumn, bool orderAsc) | SimpleNodeBaseResultSet | Returns a paginated list of email results filtered by the values of the MailFilterQuery parameter. |
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"; SimpleNodeBaseResultSet simpleNodeBaseResultSet = ws.mail.getMailsPaginated(0, 10, filter, orderColumn, true);
foreach (SimpleNodeBase simpleNodeBase in simpleNodeBaseResultSet) { System.Console.WriteLine(simpleNodeBase.toString()); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}getAccounts
Section titled “getAccounts”Description:
| Method | Return values | Description |
|---|---|---|
| getAccounts() | List |
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.getAccounts()) { System.Console.WriteLine(mail.toString()); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}getMailMessages
Section titled “getMailMessages”Description:
| Method | Return values | Description |
|---|---|---|
| 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()); } } }}addAccount
Section titled “addAccount”Description:
| Method | Return values | Description |
|---|---|---|
| addAccount(MailAccount mailAccount) | void | Add 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; ws.mail.addAccount(mailAcount); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}updateAccount
Section titled “updateAccount”Description:
| Method | Return values | Description |
|---|---|---|
| updateAccount(MailAccount mailAccount) | void | Updates 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.updateAccount(mailAcount); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}testAccount
Section titled “testAccount”Description:
| Method | Return values | Description |
|---|---|---|
| testAccount(MailAccount mailAccount) | void | Verify the 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.testAccount(mailAcount); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}deleteAccount
Section titled “deleteAccount”Description:
| Method | Return values | Description |
|---|---|---|
| deleteAccount(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.deleteAccount(mailId); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}importMessages
Section titled “importMessages”Description:
| Method | Return values | Description |
|---|---|---|
| importMessages(long mailAccountId, List |
void | Import messages from a 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.importMessages(mailAccountId, messageIds); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}createFilter
Section titled “createFilter”Description:
| Method | Return values | Description |
|---|---|---|
| createFilter(long mailAccountId, MailFilter mailFilter) | void | Add a filter to 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.createFilter(mailAccountId, filter); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}updateFilter
Section titled “updateFilter”Description:
| Method | Return values | Description |
|---|---|---|
| updateFilter(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.updateFilter(filter); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}deleteFilter
Section titled “deleteFilter”Description:
| Method | Return values | Description |
|---|---|---|
| deleteFilter(long mailFilterId) | void | Delete a filter from 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.deleteFilter(filterId); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}createRule
Section titled “createRule”Description:
| Method | Return values | Description |
|---|---|---|
| createRule(long filterId, MailFilterRule rule) | void | Create a rule for an email 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); 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.createRule(filterId, rule); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}updateRule
Section titled “updateRule”Description:
| Method | Return values | Description |
|---|---|---|
| updateRule(MailFilterRule rule) | void | Update 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); 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.updateRule(rule); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}deleteRule
Section titled “deleteRule”Description:
| Method | Return values | Description |
|---|---|---|
| deleteRule(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.deleteRule(ruleId); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}getFilterRules
Section titled “getFilterRules”Description:
| Method | Return values | Description |
|---|---|---|
| getFilterRules(long filterId) | List |
Retrieve a list of all associated filter rules. |
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.getFilterRules(filterId)) { System.Console.WriteLine(mfrule.toString()); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}forwardEmail
Section titled “forwardEmail”Description:
| Method | Return values | Description |
|---|---|---|
| forwardEmail(String uuid, List |
void | Forward an email to a list of users, roles, or external email addresses. |
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()); } } }}getPdf
Section titled “getPdf”Description:
| Method | Return values | Description |
|---|---|---|
| getPdf(String uuid) | Stream | Returns a PDF of the email. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;using com.openkm.sdk4csharp.impl;
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); Mail mail = ws.mail.getMailProperties("4b88cbe9-e73d-45fc-bac0-35e0d6e59e43"); Stream stream = ws.mail.getPdf(mail.uuid); FileStream mailFile = new FileStream("D:\\" + mail.subject + ".pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite); stream.CopyTo(mailFile); stream.Close(); mailFile.Close(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}saveAsPdf
Section titled “saveAsPdf”Description:
| Method | Return values | Description |
|---|---|---|
| saveAsPdf(String uuid, String newName, bool propertyGroups, bool security) | Document | Save the email as a PDF in the OpenKM repository. |
The value of the uuid parameter should be a Mail UUID.
When the newName parameter value is null, the document will preserve the same name.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;using com.openkm.sdk4csharp.impl;
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); Mail mail = ws.mail.getMailProperties("4b88cbe9-e73d-45fc-bac0-35e0d6e59e43"); Document docPdf = ws.mail.saveAsPdf(mail.uuid, mail.subject + ".pdf", true, true); System.Console.WriteLine("Document pdf: " + docPdf.path); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}getExtractedText
Section titled “getExtractedText”Description:
| Method | Return values | Description |
|---|---|---|
| getExtractedText(String uuid) | String | Get the extracted text. |
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.getExtractedText("50b7a5b9-89d2-430e-bbc9-6a6e01662a71")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}