How to forward mail with php-ews - php

I'll try to forward a mail with php-ews, but can't get it to work.
I have read the documentation for XML EWS
https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-respond-to-email-messages-by-using-ews-in-exchange
but I'll guess I've missed something.
$request = new CreateItemType();
$request->MessageDisposition = MessageDispositionType::SEND_AND_SAVE_COPY;
$request->Items = new NonEmptyArrayOfAllItemsType();
$request->Items->ForwardedItem = new ForwardItemType();
$request->Items->ForwardedItem->ToRecipients = new MessageType();
$request->Items->ForwardedItem->ToRecipients->Mailbox = new EmailAddressType();
$request->Items->ForwardedItem->ToRecipients->Mailbox->MailboxName = 'Foo Bar';
$request->Items->ForwardedItem->ToRecipients->Mailbox->MailboxAddress = 'Foo#Bar.com';
$request->Items->ForwardedItem->ReferenceItemId = new ItemIdType();
$request->Items->ForwardedItem->ReferenceItemId->Id = 'AAMk.....AAA=';
$request->Items->ForwardedItem->ReferenceItemId->ChangeKey = 'CQAA.....GOP';
$request->Items->ForwardedItem->NewBodyContent = new BodyContentType();
$request->Items->ForwardedItem->NewBodyContent->Value = 'Test';
$request->Items->ForwardedItem->NewBodyContent->BodyType = BodyTypeType::HTML;
The error message I'll get is:
Fatal error: Uncaught SoapFault exception: [a:ErrorInvalidRequest] Id
must be non-empty.

This doesn't look right
$request->Items->ForwardedItem->ToRecipients = new MessageType();
$request->Items->ForwardedItem->ToRecipients->Mailbox = new EmailAddressType();
$request->Items->ForwardedItem->ToRecipients->Mailbox->MailboxName = 'Foo Bar';
$request->Items->ForwardedItem->ToRecipients->Mailbox->MailboxAddress = 'Foo#Bar.com';
ToRecipients should be an array of recipient types so i think it should be
$request->Items->ForwardedItem->ToRecipients = new ArrayOfRecipientsType();
$recipient = new EmailAddressType();
$recipient->Name = 'Homer Simpson';
$recipient->EmailAddress = 'hsimpson#example.com';
$request->Items->ForwardedItem->ToRecipients->Mailbox[] = $recipient;

Related

Why am I getting a The field type's enum value is invalid for this search message?

Here is the situation.
I'm trying to get the proper class name of the serialized inventory item, however, when I'm doing a search (see the code below):
$type = new SearchEnumMultiSelectField();
$type->operator = 'anyOf';
$type->searchValue = array('serializedInventoryItem');
$search->type = $type;
$invetoryRef = new RecordRef();
$invetoryRef->internalId = '522216';
$params = new SearchMultiSelectField();
$params->operator = 'anyOf';
$params->searchValue = array($invetoryRef);
$search->serializedInventoryItem = $params;
However, when I do a search, I'm getting the following message: The field type's enum value is invalid for this search.
Why would I be getting the following error message?
Thanks!
Kevin
Found a solution, instead of using the code above, I used the following code:
$service = new NetSuiteService();
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = 522216;
$request->baseRef->type = 'serializedInventoryItem';
$getResponse = $service->get($request);
That resolved the issue.

Does not allow responding to a message sent with the moodle api

I trying to make a php script to send one message to other person in moodle.
I've seen the message api and i make this
$message = new \core\message\message();
$message->component = 'moodle';
$message->name = 'instantmessage';
$message->userfrom = 318;
$message->userto = 323;
$message->subject = 'message subject 1';
$message->fullmessage = 'message body';
$message->fullmessageformat = FORMAT_MARKDOWN;
$message->fullmessagehtml = '<p>message body</p>';
$message->smallmessage = 'small message';
$message->notification = '0';
$message->contexturl = 'http://GalaxyFarFarAway.com';
$message->contexturlname = 'Context name';
$message->replyto = "random#example.com";
$content = array('*' => array('header' => ' test ', 'footer' => ' test ')); // Extra content for specific processor
$message->set_additional_content('email', $content);
$message->courseid = 107; // This is required in recent versions, use it from 3.2 on https://tracker.moodle.org/browse/MDL-47162
$messageid = message_send($message)
The problem is, when the user 323 send a reply message in the chat that is created in the moodle internal messaging, an error occurs (the message is surrounded by red) and never arrives.
And I really want it to be able to respond as if it were a normal conversation.
I don't know if I'm going wrong.
Thank you
I finally found it !!!
The problem is that first you have to create a conversation between the users and then send the message
if(!\core_message\api::get_conversation_between_users([$userfrom, $userto ])){
$conversation = \core_message\api::create_conversation(
\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
[
$userfrom,
$userto
]
);
}
$message = new \core\message\message();
$message->component = 'moodle';
$message->name = 'instantmessage';
$message->userfrom = $userfrom ;
$message->userto = $userto;
$message->subject = 'Nuevo mensaje';
$message->fullmessage = $msg;
$message->fullmessageformat = FORMAT_MARKDOWN;
$message->fullmessagehtml = $msg;
$message->smallmessage = $msg;
$message->notification = '0';
$message->contexturl = '';
$message->contexturlname = 'Context name';
$message->replyto = "##########.###";
$content = array('*' => array('header' => '', 'footer' => ''));
$message->set_additional_content('email', $content);
$message->courseid = 107;
message_send($message);
It might be because the userto and userfrom need to be objects eg:
$userto = $DB->get_record('user', array('id' => 323));
$message->userfrom = $USER; // Current user.
$message->userto = $userto;
see https://docs.moodle.org/dev/Message_API#How_to_send_a_message

PHP consume a .net service

So i have the following web service that is found on
http://screencast.com/t/y8qM8hRDu
These are my trials and results:
Try 1:
$api_target = "http://www.xyz.co/service1.svc?wsdl"
$soap_options["location"] = $api_target;
$soap_options['trace'] = TRUE;
$soap_options['cache_wsdl'] = WSDL_CACHE_NONE;
$soap_options['style'] = SOAP_RPC;
$soap_options['use'] = SOAP_ENCODED;
$soap_options['soap_version'] = SOAP_1_2;
$client = new SoapClient($api_target,$soap_options);
$result = $client->Login(array("parameters" => $user));
Response 1:
The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/IService1/Login'.
Try 2: added SOAPaction header
$actionHeader = new SoapHeader($api_target,'SOAPAction','http://tempuri.org/IService1/Login');
$client->__setSoapHeaders($actionHeader);
$client = new SoapClient($api_target,$soap_options);
$result = $client->Login(array("parameters" => $user));
Response 2::
Bad Request
What am i doing wrong here?
By some unexplained miracle i got it working, if it helps anyone here is the revises code
$api_target = "http://www.xyz.co/service1.svc";
$api_url = $api_target."?wsdl";
$action = "http://tempuri.org/IService1/Login";
$soap_options["location"] = $api_target;
$soap_options["uri"] = $api_url;
$soap_options['trace'] = TRUE;
$soap_options['cache_wsdl'] = WSDL_CACHE_NONE;
$soap_options['style'] = SOAP_DOCUMENT;
$soap_options['use'] = SOAP_LITERAL;
$soap_options['soap_version'] = SOAP_1_2;
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing','Action',$action , true);
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing','To',$api_target ,true);
$client = new SoapClient($api_url,$soap_options);
$client->__setSoapHeaders($actionHeader);
$result = $client->__soapCall('Login',array($user));;

PHPEWS create event on public calendar

I'm attempting to plug a php based calendar management system into exchange 2007 calendars.
I have the below code setup at present.
$subject = 'Appointment with ..';
$request = new EWSType_CreateItemType();
$request->Items = new EWSType_NonEmptyArrayOfAllItemsType();
$request->Items->CalendarItem = new EWSType_CalendarItemType();
$request->Items->CalendarItem->Subject = $subject;
$date1 = new DateTime('2015-05-10T15:00:00+03:00');
$DateStart = $date1->format('Y-m-d H:i:00');
$date = new DateTime($DateStart);
$request->Items->CalendarItem->Start = $date->format('c');
$date1 = new DateTime('2015-05-10T17:00:00+03:00');
$DateEnd = $date1->format('Y-m-d H:i:00');
$date = new DateTime($DateEnd);
$request->Items->CalendarItem->End = $date->format('c');
$request->Items->CalendarItem->ReminderIsSet = false;
$request->Items->CalendarItem->ReminderMinutesBeforeStart = 15;
$request->Items->CalendarItem->Body = new EWSType_BodyType();
$request->Items->CalendarItem->Body->BodyType = EWSType_BodyTypeType::HTML;
$request->Items->CalendarItem->Body->_ = <<<EOD
<p><strong>Staff Attending</strong>:bob</p>
EOD;
$request->Items->CalendarItem->ItemClass = new EWSType_ItemClassType();
$request->Items->CalendarItem->ItemClass->_ = EWSType_ItemClassType::APPOINTMENT;
$request->Items->CalendarItem->Sensitivity = new EWSType_SensitivityChoicesType();
$request->Items->CalendarItem->Sensitivity->_ = EWSType_SensitivityChoicesType::NORMAL;
$request->Items->CalendarItem->Categories = new EWSType_ArrayOfStringsType();
$request->Items->CalendarItem->Categories->String = array(
'Client Meeting (Scheduled)'
);
$request->Items->CalendarItem->Location = "Showroom";
$request->SendMeetingInvitations = EWSType_CalendarItemCreateOrDeleteOperationType::SEND_ONLY_TO_ALL;
$request->Items->CalendarItem->RequiredAttendees->Attendee[0]->Mailbox->EmailAddress = "user#domain.com";
$request->Items->CalendarItem->RequiredAttendees->Attendee[0]->Mailbox->RoutingType = 'SMTP';
$n = 1;
$response = $ews->CreateItem($request);
This will setup an event in the users personal calendar just fine, but what I need to do is to get it to post to a public folder calendar which I have the folderID for.
If anyone could assist it would be greatly appreciated!
Try adding the line:
$request->SavedItemFolderId->FolderId->Id=$folder_id;
after the
$request = new EWSType_CreateItemType();
where $folder_id is your stupidly long microsoft folder id!!!!
I'm doing the same right now.
You have to replace the SEND_ONLY_TO_ALL with SEND_TO_NONE.
This means that we cannot send meeting invitations for appointments stored in a public folder (I've been trying to find a workaround for this problem for a couple weeks now).
I'm not sure if there are other problems in your request but this is surely an issue.

LendingClub API OrderSubmitOrders action

I am attempting to interface with the LendingClub API using SOAP. I've generated some classes using wsdl2php.
The wsdl file can be found here: https://www.lendingclub.com/ws/1.3?wsdl
I've successfully executed 4 of the 5 API methods, but the submit order method results in the following error:
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR:
Encoding: Violation of encoding rules
Code exert (integer IDs replaced by XXXXXX:
$order = new Order();
$order->loanId = XXXXXX;
$order->requestedAmount = 25.00;
$order->portfolioId = XXXXXX;
$order_instruct = new OrderInstruct();
$order_instruct->aid = XXXXXX;
$order_instruct->orders = $order;
$submit_order = new OrderSubmitOrders();
$submit_order->instructs = $order_instruct;
$submit_order_response = $lendingClub->OrderSubmitOrders($submit_order);
var_dump($submit_order_response);
Thanks in advance.
$my_order= new Order();
$my_order->loanId = $soapResponse->result->loans[0]->id;
$my_order->requestedAmount = 'xxx';
$my_order->portfolioId = 'xxxxxxxxx';
$instruct = new OrderInstruct();
$instruct->aid = "xxxxxxxxx";
$instruct->orders = array(my_order);
$orderSubmitObject = new OrderSubmitOrders();
$orderSubmitObject->instructs = $instructs;
$lendingClub->OrderSubmitOrders($orderSubmitObject);

Categories