1

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!

Georgi Bilyukov
  • 645
  • 4
  • 11

2 Answers2

1

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;
DanielJay
  • 292
  • 3
  • 13
0

I'm not realy familiar with php, but if I'm using C# the mailmessage-class has a "Importance" property which is an enum and can be set to: High, Low and Normal. Default is "Normal".

Hope this helps you...

Jürgen Hoffmann
  • 947
  • 4
  • 15
  • You probably use the EWS Managed API for C#, which a wrapper for the EWS web service. In my case I cannot use it. Thank you for your response. – Georgi Bilyukov Mar 27 '13 at 13:28