<?php require_once "vendor/autoload.php"; use garethp\ews\API\Type; use garethp\ews\MailAPI; //This one is a bit trickier. Rather than sending the email directly, we have to first create the email, then create the //attachments, then send the email. $api = MailAPI::withUsernameAndPassword('server', 'username', 'password'); $message = new Type\MessageType(); $message->setBody('Some Text'); $message->setSubject('Test Subject'); $message->setToRecipients('*****@*****.**'); //Create our message without sending it $mailId = $return = $api->sendMail($message, array('MessageDisposition' => 'SaveOnly')); //Create our Attachments $api->getClient()->CreateAttachment(array('ParentItemId' => $mailId->toArray(), 'Attachments' => array('FileAttachment' => array('Name' => 'picture.jpg', 'Content' => file_get_contents('picture.jpg'))))); //We need to fetch the ItemId again. This is because the ItemId contains a "ChangeKey", which is an Id for that specific //version of the item. Since we've added attachments, the item has changed, so we need to get the new change key before //we can send the message $mailId = $api->getItem($mailId)->getItemId(); //Send the message $api->getClient()->SendItem(array('SaveItemToFolder' => true, 'ItemIds' => array('ItemId' => $mailId->toArray())));
<?php require_once "vendor/autoload.php"; use garethp\ews\API\Type; $api = MailApi::withUsernameAndPassword('server', 'username', 'password'); //Create the message item $message = new Type\MessageType(); $message->setSubject('Test Message'); $message->setBody('Test Draft Body'); //Set the message as not a draft using extended property types $extended = new Type\ExtendedPropertyType(); $fieldUri = new Type\ExtendedFieldURI(); $fieldUri->setPropertyTag("0x0E07"); $fieldUri->setPropertyType(\garethp\ews\API\Enumeration\MapiPropertyTypeType::INTEGER); $extended->setExtendedFieldURI($fieldUri); $extended->setValue(1); $message->addExtendedProperty($extended); //Pass it to the Send Mail function, but to SaveOnly without actually sending the email $itemId = $api->sendMail($message, array('MessageDisposition' => 'SaveOnly')); //Move the mail message from the sent folder to whatever folder we want to send it to $api->getClient()->MoveItem(Type::buildFromArray(array('ToFolderId' => array('FolderId' => $folderId->toArray()), 'ItemIds' => array('ItemId' => $itemId->toArray()))));
public function testGetUnreadMailItems() { $client = $this->getClient(); $unreadItems = $client->getUnreadMailItems(); $this->assertCount(0, $unreadItems); $this->createTestMail(); $unreadItems = $client->getUnreadMailItems(); $this->assertCount(0, $unreadItems); $message = new Type\MessageType(); $message->setSubject('Test Message'); $message->setBody('Test Draft Body'); $message->setIsRead(false); $this->createTestMail($message); $unreadItems = $client->getUnreadMailItems(); $this->assertCount(1, $unreadItems); }