I am using php-ews to send mails and I cannot find a way to set the importance (priority) of a mail. Here is my code:
$from = $mail['from'];
$to = $mail['to'];
$subject = $mail['subject'];
$body = $mail['body'];
$msg = new EWSType_MessageType();
if($to && count($to) > 0){
$toAddresses = $this->getAddresses($to);
$msg->ToRecipients = $toAddresses;
}
$fromAddress = new EWSType_EmailAddressType();
$fromAddress->EmailAddress = $from['mail'];
$fromAddress->Name = $from['name'];
$msg->From = new EWSType_SingleRecipientType();
$msg->From->Mailbox = $fromAddress;
$msg->Subject = $subject;
$msg->Body = new EWSType_BodyType();
$msg->Body->BodyType = 'HTML';
$msg->Body->_ = $body;
$msgRequest = new EWSType_CreateItemType();
$msgRequest->Items = new EWSType_NonEmptyArrayOfAllItemsType();
$msgRequest->Items->Message = $msg;
$msgRequest->MessageDisposition = 'SendAndSaveCopy';
$msgRequest->MessageDispositionSpecified = true;
$response = $this->ews->CreateItem($msgRequest);
return $response;
Thank you in advance for your response!
You need to load the EWSType_ImportanceChoicesType class. Your code should look like this:
$from = $mail['from'];
$to = $mail['to'];
$subject = $mail['subject'];
$body = $mail['body'];
$msg = new EWSType_MessageType();
if($to && count($to) > 0){
$toAddresses = $this->getAddresses($to);
$msg->ToRecipients = $toAddresses;
}
$fromAddress = new EWSType_EmailAddressType();
$fromAddress->EmailAddress = $from['mail'];
$fromAddress->Name = $from['name'];
$msg->From = new EWSType_SingleRecipientType();
$msg->From->Mailbox = $fromAddress;
$msg->Subject = $subject;
$msg->Body = new EWSType_BodyType();
$msg->Body->BodyType = 'HTML';
$msg->Body->_ = $body;
$msgRequest = new EWSType_CreateItemType();
$msgRequest->Items = new EWSType_NonEmptyArrayOfAllItemsType();
$msgRequest->Items->Message = $msg;
// Start importance code
$msgRequest->Items->Message->Importance = new EWSType_ImportanceChoicesType();
$msgRequest->Items->Message->Importance->_ = EWSType_ImportanceChoicesType::HIGH;
// End importance code
$msgRequest->MessageDisposition = 'SendAndSaveCopy';
$msgRequest->MessageDispositionSpecified = true;
$response = $this->ews->CreateItem($msgRequest);
return $response;
To change the importance just change the ending of the following line to have HIGH, LOW or NORMAL:
$msgRequest->Items->Message->Importance->_ = EWSType_ImportanceChoicesType::HIGH;