PHP-EWS: UploadItem using PHP for .EML-Files - php

*,
I want to upload daily some .EML-Files to my Exchange Server 2013. So I found from Google a PHP class from James Iarmes calles PHP-EWS.
https://github.com/jamesiarmes/php-ews
I tried some examples and I think, this class is good for me. There is only one problem: no example-code in this wiki and unfortunately I do not get it out :-(
Is there someone, who works with this class and can post a example to do uploads to Exchange-Servers using PHP-EWS?
Regards

Based on the answer given by Michael up above, I can't tell you how you'd do it in jamesaires/php-ews, but I can tell you how to do it in my ews library, garethp/php-ews. I'd highly recommend you look in to my library instead, as it's maintained and PSR-4 compatible. Here's how you'd do it using Michael's method
<?php
require_once "vendor/autoload.php";
use jamesiarmes\PEWS\API\Type;
use jamesiarmes\PEWS\Mail\MailAPI;
$api = MailApi::withUsernameAndPassword('server', 'username', 'password');
$message = new Type\MessageType();
$message->setMimeContent(file_get_contents('./file.eml'));
//Set the message as not a draft using extended property types
$extended = new Type\ExtendedPropertyType();
$fieldUri = new Type\ExtendedFieldURI();
$fieldUri->setPropertyTag("0x0E07");
$fieldUri->setPropertyType(\jamesiarmes\PEWS\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'));
$inbox = $api->getFolderByDistinguishedId('inbox');
//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' => $inbox->getFolderId()->toArray()),
'ItemIds' => array(
'ItemId' => $itemId->toArray()
)
)));

I've never worked with PHP-EWS but I do know that you can put a .eml into Exchange.You won't be using the UploadItem operation. You'll use the CreateItem operation. Here's the workflow:
Create an email object.
Set the MimeContent property with the contents of your .eml file.
Set the PR_MESSAGE_FLAGS_msgflag_read property.
Use the CreateItem operation, or whatever the client-side equivalent is in PHP-EWS.
I'm fairly confident that this will work as I remember writing this in the official documentation.

Related

Generate EML file for DKIM Signatue

Some question's, and articles I've been reading regarding EML creation
How to verify DKIM signature from an e-mail with openssl?
PHP library to generate EML email files?
https://www.icosaedro.it/phplint/mailer-tutorial/index.html
https://coderedirect.com/questions/25620/php-library-to-generate-eml-email-files (This one is interesting, but it would need extending for DKIM signatures)
https://www.example-code.com/phpExt/smtp_loadEmlAndSend.asp (only does SMTP send)
https://community.apachefriends.org/f/viewtopic.php?t=79968&p=270281 (this works great for Linux, haven't been able to find Windows equivalent)
Use of mailtodisk / mailoutput in XAMPP for Linux (Great concept)
https://swiftmailer.symfony.com/docs/introduction.html (This is from Symfony yet to see if works without Symfony but no longer maintained)
I can't seem to find any standalone class files that will generate the contents for *.eml that can be either stored into file (using file_put_contents) or temporarily into a variable.
The idea is that I can create my *.eml file server-side I could use the contents to verify a DKIM signature, without having to actually send an email.
I did find one library phplint that does what I want, but it is far too big for what I need (635 Files, 53 Folders 7.84 MB (8,224,768 bytes)).
$m = new Mailer();
$m->setSubject("This is the subject");
$m->setFrom("my#mydomain.com", "My Name");
$m->addAddress("you#yourdomain.com", "Your Name");
$m->setTextMessage("This is the text body of the message.");
$m->sendByStream($out_string, TRUE);
$message_as_string = $out_string->__toString();
The above snippet uses the following classes to generate the message.
[180] => it\icosaedro\email\Mailer
[181] => it\icosaedro\io\IOException
[182] => it\icosaedro\utils\StringBuffer
[183] => it\icosaedro\io\OutputStream
[184] => it\icosaedro\io\StringOutputStream
[185] => it\icosaedro\email\Field
[186] => it\icosaedro\email\MIMEAbstractPart
[187] => it\icosaedro\email\Header
[188] => it\icosaedro\email\MIMEPartMemory
[189] => it\icosaedro\email\EOLFilter
[190] => it\icosaedro\utils\Random
I've been looking all over github, as well as PHPClasses. But I can't anything relevant to what I need (with enough research I could probably build it myself but I'd prefer not to reinvent the wheel).
Ideally I'm looking for possibly an extension of PHPMailer, that can stream the EMAIL either to File or String Variable). I also need the class or function to work on both linux and windows.
If somebody can just find a library or point me into the right direction, I'd much appreciate it.
I think I've found what I've been looking for with https://symfony.com/doc/current/mailer.html
$email = (new Email())
->from('hello#example.com')
->to('you#example.com')
//->cc('cc#example.com')
//->bcc('bcc#example.com')
//->replyTo('fabien#example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Time for Symfony Mailer!')
->text('Sending emails is fun again!')
->html('<p>See Twig integration for better HTML integration!</p>');
echo "<pre>";
print_r($email->toString());
echo "</pre>";
Although I'm still looking for a single class solution rather downloading an bloatware to fulfil a single task.

What does this email from SendGrid is refering to in PHP API?

a few days a go we received a email from sendgrid stating they are going to change some behaviors in their API, I've done research but I have not found concretly what they are refering to, currently we are using the PHP API, and atleast for the 2) I think we are OK as we use SendGrid classes to build the emails
Check your code that uses the mail send endpoint and ensure that the
“enable” parameter is included under the filter when applicable.
What do you need to do?
To avoid disruption to your mail send service, please be sure to make
the following actions before August 10, 2021
Check your code that uses the mail send endpoint and ensure that the
“enable” parameter is included under the filter when applicable.
Check your mail send header to ensure that you are using just one
X-SMTPAPI header and address header of the same kind. Remove multiple
headers of the same kind, so you have only 1 header of the same kind.
For example, if you are currently using multiple “from” headers, you
should modify your code so that you have a single “from” header.
Check your code to ensure that you are not applying any
personalization block substitution to your custom argument fields.
But what about the third item? we have substitions of following fashion: $mail->personalization[0]->addSubstitution('%url%', $link);
But I havent found anything like a "block sustitution in custom arguments"
And the first item also worries me, I haven't found anything like that neither, so I'm afraid that perhaps there is something that the PHP API does behind the scenes.
This a example of the code we use.
$sendgrid = new SendGrid(env('SENDGRID_APIKEY'));
$from_m = new SendGrid\Email(null, $from);
$to_m = new SendGrid\Email(null, $from);
$content = new SendGrid\Content("text/html", $body);
$mail = new SendGrid\Mail($from_m, '.', $to_m, $content);
$mail->personalization[0]->addBcc($tos);
$mail->personalization[0]->setSubject($subject);
$mail->personalization[0]->addSubstitution('%MemberName%', $name);
$mail->personalization[0]->addSubstitution('%url%', $hash_url);
$mail->setTemplateId($template_id);
$sendgrid->client->mail()->send()->post($mail);
We are using sendgrid/sendgrid: ~6.2
Twilio SendGrid developer evangelist here.
From my reading of your code and the guidelines you've been sent, you should be ok.
You don't appear to be using anything that needs to be enabled via the API, though you can check all the mail_settings and tracking_settings in the API reference here.
As you are using the library and calling the API you don't appear to be sending any extra headers.
You don't seem to be using any custom arguments, so you aren't applying any substitutions to them.
I do recommend that you upgrade your PHP helper library to version 7 from 6. That will ensure that the underlying library is also using the API in the most up to date manner.

how to use GET to obtain info from a URL

I'm a php programmer but I'm new to APIs.
I would like to run a mysql query to get info from an XML document from madmimi.com.
documentation from madmimi.com says
GET http://madmimi.com/audience_lists/lists.xml will return the data I need. I've created a php file and connected to their API using
require(dirname(FILE) . '/MadMimi.class.php');
$mailer = new MadMimi('username', 'password');
but I don't understand how to use GET to connect to the URL and display the XML info?
What do I need to do?
All http api interaction is hidden to you behind their library. You can use it's methods to grab objects, like this to lists:
$mailer->Lists();
There is no complete documentation, but you can read raw code to search urls, described in API for finding appreciated methods.
You can use curl to get the response from the 3rd party api. Have a look at this answer:
https://stackoverflow.com/a/5159513/1369567
Based upon the code in answer given at that link, you may need to the code to match your request. E.g:
/* Script URL */
$url = 'http://madmimi.com/audience_lists/lists.xml';
/* $_GET Parameters to Send */
$params = array('username' => '*your api username*', 'password' => '*your api password*');

Jira Soap with a Php

I have seen little to know instruction on using php to develop a client website to make remote calls to JiRA.
Currently I'm trying to make a soap client using JSP/Java to connect to a local jira instance. I would like to create and search issues that is all. We are currently having some problems using Maven2 and getting all the files we need from the repository since we are behind a major firewall(yes I've used the proxy).
I have a lot of experience with PHP and would like to know if using the PHP soapclient calls can get the job done.
http://php.net/manual/en/soapclient.soapclient.php
Yes it can be done, using SOAP or XML-RPC.
Using the APIs is pretty much straight forward - have a look at the API documentation to find the right functions for you. your code should look something like :
<?
$soapClient = new SoapClient("https://your.jira/rpc/soap/jirasoapservice-v2?wsdl");
$token = $soapClient->login('user', 'password');
...
... # get/create/modify issues
...
?>
Example of adding a new comment:
$issueKey = "key-123";
$myComment = "your comment";
$soapClient = new SoapClient("https://your.jira/rpc/soap/jirasoapservice-v2?wsdl");
$token = $soapClient->login('user', 'password');
$soapClient->addComment($token, $issueKey, array('body' => $myComment));
Example of creating an issue:
$issue = array(
'type'=>'1',
'project'=>'TEST',
'description'=>'my description',
'summary'=>'my summary',
'priority'=>'1',
'assignee'=>'user',
'reporter'=>'user',
);
$soapClient = new SoapClient("https://your.jira/rpc/soap/jirasoapservice-v2?wsdl");
$token = $soapClient->login('user', 'password');
$soapClient->createIssue($token, $issue);
Note that you need to install php-soap in linux (or it's equivalent in windows) to be able to use the SOAP library.

Exchange Server 2007 Web Services PHP Class

Does anyone know of an open source PHP class (preferably BSD or MIT license) that will interface with the MS Exchange Server 2007 Web Services via. SOAP?
I am looking for a higher level class that has functionality for sending messages via. the web service.
I had this same problem, so I started building something, here:
https://github.com/rileydutton/Exchange-Web-Services-for-PHP
It doesn't do much yet (basically just lets you get a list of email messages from the server, and send email), but it would be good enough to use as a basic starting point for doing some more complicated things.
I have abstracted out a good bit of the complexity that you would have to slog through using php-ews. If you are looking to do some raw, powerful commands with the server, I would use php-ews...this is for folks who just happen to be working with an Exchange server and want an easy way to do some basic tasks.
Oh, and it is MIT licensed.
Hope that someone finds it useful!
Here is a class that you need: php-ews (This library makes Microsoft Exchange 2007 Web Services easier to implement in PHP).
You could find it at: http://code.google.com/p/php-ews/
There is only one example but that should give you the way to implement it.
Below you can find an implementation in order to:
connect to server
get the calendar events
Note: don't forget to fill-in blank variables. You would also need to include php-ews classes files (I used the __autoload PHP function).
$host = '';
$username = '';
$password = '';
$mail = '';
$startDateEvent = ''; //ie: 2010-09-14T09:00:00
$endDateEvent = ''; //ie: 2010-09-20T17:00:00
$ews = new ExchangeWebServices($host, $username, $password);
$request = new EWSType_FindItemType();
$request->Traversal = EWSType_FolderQueryTraversalType::SHALLOW;
$request->CalendarView->StartDate = $startDateEvent;
$request->CalendarView->EndDate = $endDateEvent;
$request->CalendarView->MaxEntriesReturned = 100;
$request->CalendarView->MaxEntriesReturnedSpecified = true;
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = $mail;
$response = $ews->FindItem($request);
echo '<pre>'.print_r($response, true).'</pre>';
Exchange server supports WebDAV:
http://www.troywolf.com/articles/php/exchange_webdav_examples.php
If all you want to do is send messages, you could just use SMTP:
http://ca2.php.net/manual/en/book.mail.php
I have been researching this same issue and I have yet to find a class specific to MS Exchange. However, if you feel up to learning and building the XML yourself, you may want to have a look at the NTLM SOAP classes at http://rabaix.net/en/articles/2008/03/13/using-soap-php-with-ntlm-authentication. This will allow you to authenticate against Active Directory to make your SOAP calls, which native PHP SOAP does not allow you to do. Another decent resource that uses the same method to connect to MS CRM is http://www.reutone.com/heb/articles_internet.php?instance_id=62&actions=show&id=521.
The examples under http://www.troywolf.com/articles/php/exchange_webdav_examples.php are for Exchange 2003 not 2007.

Categories