Mail samples
Basics
On most 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 -> "520f4d98-1855-4784-9bc3-01ba5b440c1d";
- 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 returns as a result an object Mail. |
The variable path into the parameter mail, must be initializated. It indicates the folder path into OpenKM. Other mandatory variables:
Mails account allowed formats:
Mail path allowed is: MSGID . "-" . sanitized(subject). MIME types values:
Origin values:
The other variables of Mail ( mail ) will not take any effect on mail creation. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testCreateMail() {
try {
$mail = new \openkm\bean\Mail();
// Mail path = msgId + escaped(subject)
$msgId = "2937b81d-0b10-4dd0-a426-9acbd80be1c9";
$subject = "some subject";
$mailPath = "/okm:root/SDK4PHP/" . $msgId . "-" . $this->escape($subject);
$mail->setPath($mailPath);
// Other format for mail "some name <no_reply@openkm.com>"
$mail->setFrom('<no_reply@openkm.com>');
$mail->setTo(['anonymous@gmail.com', 'anonymous1@gmail.com']);
// You should set real dates
$mail->setSentDate(date('Y-m-d'));
$mail->setReceivedDate(date('Y-m-d'));
$mail->setContent('some content');
$mail->setMimeType(\openkm\bean\Mail::MIME_TEXT);
$mail->setSubject($subject);
$mail->setOrigin(\openkm\bean\Mail::ORIGIN_API);
// Get only as an approximation of real size for these sample
$mail->setSize(strlen($mail->toString()));
var_dump($this->ws->createMail($mail));
} catch (Exception $e) {
var_dump($e);
}
}
private function escape($name) {
$ret = $this->cleanup($name);
return htmlentities($ret);
}
private function cleanup($name) {
$ret = str_replace('/', '', $name);
$ret = str_replace('*', '', $ret);
$ret = str_replace('\\s+', ' ', $ret);
return $ret;
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testCreateMail();
?>
getMailProperties
Description:
Method | Return values | Description |
---|---|---|
getMailProperties($mailId) |
|
Returns the mail properties. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetMailProperties() {
try {
$mail = $this->ws->getMailProperties('520f4d98-1855-4784-9bc3-01ba5b440c1d');
var_dump($mail);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testGetMailProperties();
?>
deleteMail
Description:
Method | Return values | Description |
---|---|---|
deleteMail($mailId) |
void |
Deletes a mail. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testDeleteMail() {
try {
$this->ws->deleteMail('520f4d98-1855-4784-9bc3-01ba5b440c1d');
echo 'deleted';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testDeleteMail();
?>
renameMail
Description:
Method | Return values | Description |
---|---|---|
renameMail($mailId, $newName) |
|
Change the name of a Mail and returns the Mail |
Parameters: $newName string type is the new name for the Mail From OpenKM frontend UI the subject is used to show the mail name at file browser table. That means this change will take effect internally on mail path, but will not be appreciated from default UI. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testRenameMail() {
try {
$mail = $this->ws->renameMail('520f4d98-1855-4784-9bc3-01ba5b440c1d', 'new name');
var_dump($mail);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testRenameMail();
?>
moveMail
Description:
Method | Return values | Description |
---|---|---|
moveMail($mailId, $dstId) |
void |
Moves mail into a folder or record. |
Parameters: $dstId string type is the uuid or path of the Folder or Record |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testMoveMail() {
try {
$this->ws->moveMail('520f4d98-1855-4784-9bc3-01ba5b440c1d', '/okm:root/SDK4PHP/tmp');
echo 'move';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testMoveMail();
?>
getMailChildren
Description:
Method | Return values | Description |
---|---|---|
getMailChildren($fldId) |
array |
Returns a list of all mails which their parent is fldId. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetMailChildren() {
try {
$mails = $this->ws->getMailChildren('/okm:root/SDK4PHP');
foreach ($mails as $mail) {
var_dump($mail);
}
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testGetMailChildren();
?>
isValidMail
Description:
Method | Return values | Description |
---|---|---|
isValidMail($mailId) |
bool |
Returns a boolean that indicate if the node is a mail or not. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testIsValidMail() {
try {
//Return false
var_dump($this->ws->isValidMail('/okm:root/SDK4PHP/logo.png'));
//Return true
var_dump($this->ws->isValidMail('520f4d98-1855-4784-9bc3-01ba5b440c1d'));
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testIsValidMail();
?>
getMailPath
Description:
Method | Return values | Description |
---|---|---|
getMailPath($uuid) |
string |
Converts mail UUID to mail path. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetMailPath() {
try {
var_dump($this->ws->getMailPath('520f4d98-1855-4784-9bc3-01ba5b440c1d'));
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testGetMailPath();
?>
createAttachment
Description:
Method | Return values | Description |
---|---|---|
createAttachment($mailId, $docName, $content) |
Document |
Stores into the mail an attachment and returns an object Document with the properties of the created attachment. |
Parameters: $docName string type is the Name of the Attachment $content string type is recommend using file_get_contents — Reads entire file into a string |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testCreateAttachment() {
try {
$fileName = dirname(__FILE__) . '/files/logo.png';
$docName = 'logo.png';
$document = $this->ws->createAttachment('520f4d98-1855-4784-9bc3-01ba5b440c1d', $docName, file_get_contents($fileName));
var_dump($document);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testCreateAttachment();
?>
deleteAttachment
Description:
Method | Return values | Description |
---|---|---|
deleteAttachment($mailId, $docId) |
void |
Deletes a mail attachment. |
Parameters: $docId string type is the uuid or path of the Document |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testDeleteAttachment() {
try {
$this->ws->deleteAttachment('520f4d98-1855-4784-9bc3-01ba5b440c1d', '73ba1f80-4769-492b-ab15-0ecfbb15d6ac');
echo 'deleted attachment';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testDeleteAttachment();
?>
getAttachments
Description:
Method | Return values | Description |
---|---|---|
getAttachments(String mailId) |
array |
Retrieves a list of all documents attachment of a mail. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetAttachments() {
try {
$documents = $this->ws->getAttachments('520f4d98-1855-4784-9bc3-01ba5b440c1d');
foreach ($documents as $document) {
var_dump($document);
}
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testGetAttachments();
?>
purgeMail
Description:
Method | Return values | Description |
---|---|---|
purgeMail($mailId) |
void |
Mail is definitely removed from repository. |
Parameters: 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 only will be able to be restored from a previously repository backup. The purge action remove the mail definitely from the repository. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testPurgeMail() {
try {
$this->ws->purgeMail('520f4d98-1855-4784-9bc3-01ba5b440c1d');
echo 'purge';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testPurgeMail();
?>
copyMail
Description:
Method | Return values | Description |
---|---|---|
public void copyMail($mailId, $dstId, $newName) |
void |
Copies mail into a folder or record. |
Parameters: $dstId string type is the uuid or path of the Folder or Record $newName string type is the new name for the Document When parameter newName value is null, mail will preserve the same name. Only the security grants are copied to destination, the metadata, keywords, etc. of the folder are not copied. See "extendedMailCopy" method for this feature. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testCopyMail() {
try {
$this->ws->copyMail('520f4d98-1855-4784-9bc3-01ba5b440c1d', '/okm:root/SDK4PHP/tmp', 'new_name');
echo 'copyMail';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testCopyMail();
?>
extendedMailCopy
Description:
Method | Return values | Description |
---|---|---|
extendedMailCopy($mailId, $dstId, $categories, $keywords, $propertyGroups, $notes, |
void |
Copies mail width with associated data into a folder or record. |
Parameters: $dstId string type is the uuid or path of the Folder or Record $categories bool type $keywords bool type $propertyGroups bool type $notes bool type $wiki bool type $newName string type is the new name for the Mail. Value is null, mail will preserve the same name. By default only the binary data and the security grants, the metadata, keywords, etc. of the folder are not copied. Additional:
|
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testExtendedMailCopy() {
try {
$this->ws->extendedMailCopy('3c19ceb2-9c6a-4b43-aabb-7f169127022a', '/okm:root/SDK4PHP/tmp', true, true, true, true, true, 'new_name_copy');
echo 'extendedMailCopy';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testExtendedMailCopy();
?>
sendMailWithAttachments
Description:
Method | Return values | Description |
---|---|---|
sendMailWithAttachments($subject, $body, $dstId, $toRecipients, $ccRecipients, $bccRecipients, $docsId) |
void |
Sends mail message with attachement. |
Parameters: $body string type is the message of the email $dstId string type is the uuid or path of the Folder or Record $toRecipients array type are a array of mail accounts destination $ccRecipients array type are a array of mail accounts destination (optinal) $bccRecipients array type are a array of mail accounts destination (optional) $docsId array type are a array of valid document UUID already into OpenKM that will be send as attachment into mail ( optional ). |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testSendMailWithAttachments() {
try {
$to = ['destination@gmail.com','destination1@gmail.com'];
$cc = ['destination3@gmail.com','destination4@gmail.com'];
$bcc = ['destination5@gmail.com','destination6@gmail.com'];
$docsId = ['f123a950-0329-4d62-8328-0ff500fd42db','/okm:root/SDK4PHP/logo.png'];
$this->ws->sendMailWithAttachments('some suject', 'some body', '/okm:root/SDK4PHP/tmp', $to, $cc, $bcc, $docsId);
echo 'sendMailWithAttachemetns';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testSendMailWithAttachments();
?>
importEml
Description:
Method | Return values | Description |
---|---|---|
importEml($dstId, $title, $content) |
|
Import a mail in EML format. |
Parameters: $title string type is the title of the Mail. $content string type is recommend using file_get_contents — Reads entire file into a string |
Example:
<?php
include '../src/openkm/OpenKM.php';
ini_set('display_errors', true);
error_reporting(E_ALL);
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testImportEml() {
try {
$fileName = dirname(__FILE__) . '/files/test.eml';
$mail = $this->ws->importEml('768748c5-04ab-4921-b0d4-7545d239ce5a', 'some title', file_get_contents($fileName));
var_dump($mail);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testImportEml();
?>
importMsg
Description:
Method | Return values | Description |
---|---|---|
importMsg($dstId, $title, $content) |
Mail |
Import a mail in MSG format. |
Parameters: $title string type is the title of the Mail. $content string type is recommend using file_get_contents — Reads entire file into a string |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testImportMsg() {
try {
$fileName = dirname(__FILE__) . '/files/test.eml';
$mail = $this->ws->importEml('702e456a-3145-4dd5-831d-01647a9f2608', 'some title', file_get_contents($fileName));
var_dump($mail);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testImportMsg();
?>
setMailTitle
Description:
Method | Return values | Description |
---|---|---|
setMailTitle($mailId, $title) |
void |
Import a mail in MSG format. |
Parameters: $title string type is the title of the Mail. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testSetMailTitle() {
try {
$this->ws->setMailTitle('3c19ceb2-9c6a-4b43-aabb-7f169127022a', 'some title');
echo 'mail title';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testSetMailTitle();
?>
sendMail
Description:
Method | Return values | Description |
---|---|---|
sendMail($subject, $body, $recipients) |
void |
Sends a mail. |
Parameters: $body string type is the message of the email. $recipients string type is array of mail accounts destination |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleMail {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testSendMail() {
try {
$recipients = array();
$recipients[] = 'gnu.java.sergio@gmail.com';
$recipients[] = 'sochoa@openkm.com';
$this->ws->sendMail('Testing sending mail from OpenKM', 'Test message body.', $recipients);
echo 'send Mail';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleMail = new ExampleMail();
$exampleMail->testSendMail();
?>