0

I am new to Symfony and I managed to create a simple Symfony2.3.5 app that is supposed to send (Only send) automated e-mails through a Microsoft Exchange Server 2007, I have a user and a password; a normal e-mail user, and I can use this user to send e-mails with Outlook or Evolution in Linux using the API for exchange. But I have no Idea about how to send e-mails from the, Symfony app to the this server and then the server is supposed to deliver as any normal e-mail from my user. Any one who has done this before with MS exchange? Any Doc that I can read to get an IDEA of how does it works?

I have been reading about PhpEws, but i do not know if it will work for this situation and I do not know ether how to add it to Symfony, I have tried, but I didn't managed, that's why I decided to ask about this issue. Regards and thank you!

Abel
  • 538
  • 5
  • 8
  • 28
  • I do not know what happen; is the question too difficult, too silly, too out of context? Shall I clarify any thing else? Are we on leave? Am I asking for too much? There is no existing technical solution for this? Any one has any IDEA? – Abel Oct 29 '13 at 05:59

1 Answers1

1

Apparently I managed to make it work with Php-Ews, The with the method i have used it works even if I know is not the correct way to do it. I have included the Php-Ews folder in the Controller folder of my project. I have created a new route that responds to /emails and then inside I have added this in the controller:

namespace Osd\RetireBundle\Controller;

use Symfony\Component\HttpFoundation\Response;
use PhpEws\ExchangeWebServices;

class EmailsController {
public function indexAction()
{

    $this->sendEmail();

    return new Response('<html><body>Hello !</body></html>');
}
protected function sendEmail(){
    $PhpEwsPath = __DIR__."/php-ews/";

    require_once $PhpEwsPath.'ExchangeWebServices.php';
    require_once $PhpEwsPath.'NTLMSoapClient.php';
    require_once $PhpEwsPath.'NTLMSoapClient/Exchange.php';
    require_once $PhpEwsPath.'EWS_Exception.php';
    require_once $PhpEwsPath.'EWSType.php';
    require_once $PhpEwsPath.'EWSType/MessageType.php';
    require_once $PhpEwsPath.'EWSType/EmailAddressType.php';
    require_once $PhpEwsPath.'EWSType/BodyType.php';
    require_once $PhpEwsPath.'EWSType/SingleRecipientType.php';
    require_once $PhpEwsPath.'EWSType/CreateItemType.php';
    require_once $PhpEwsPath.'EWSType/NonEmptyArrayOfAllItemsType.php';
    require_once $PhpEwsPath.'EWSType/ItemType.php';        


    $server = 'server';
    $username = 'username';
    $password = 'password';  
    $ews = new \ExchangeWebServices($server, $username, $password);

    $msg = new \EWSType_MessageType();

    $toAddresses = array();
    $toAddresses[0] = new \EWSType_EmailAddressType();
    $toAddresses[0]->EmailAddress = 'email@example.com';
    $toAddresses[0]->Name = 'John Doe';   

    /*$toAddresses[1] = new \EWSType_EmailAddressType();
    $toAddresses[1]->EmailAddress = 'email2@example.com';
    $toAddresses[1]->Name = 'Richard Roe';  

    $toAddresses[2] = new \EWSType_EmailAddressType();
    $toAddresses[2]->EmailAddress = 'email3@example.com';
    $toAddresses[2]->Name = 'Hustle and Flow';        

    $toAddresses[3] = new \EWSType_EmailAddressType();
    $toAddresses[3]->EmailAddress = 'email4@example.com';
    $toAddresses[3]->Name = 'Crookedeye Moe';*/     

    $msg->ToRecipients = $toAddresses;

    $fromAddress = new \EWSType_EmailAddressType();
    $fromAddress->EmailAddress = 'email@example.com';
    $fromAddress->Name = 'Abel';

    $msg->From = new \EWSType_SingleRecipientType();
    $msg->From->Mailbox = $fromAddress;

    $msg->Subject = 'Test email message from RAS';

    $msg->Body = new \EWSType_BodyType();
    $msg->Body->BodyType = 'HTML';
    $msg->Body->_ = '<p style="font-size: 18px; font-weight: bold;">Test email message from php ews library from RAS.</p>';

    $msgRequest = new \EWSType_CreateItemType();
    $msgRequest->Items = new \EWSType_NonEmptyArrayOfAllItemsType();
    $msgRequest->Items->Message = $msg;
    $msgRequest->MessageDisposition = 'SendAndSaveCopy';
    $msgRequest->MessageDispositionSpecified = true;

    $response = $ews->CreateItem($msgRequest);
    var_dump($response);        
}

}

And let me tell you what... IT WORKS!! Now I need your help to organize it properly. where is the right place to add the function or class that I create for this. Thank you in advanced.

Shog9
  • 156,901
  • 35
  • 231
  • 235
Abel
  • 538
  • 5
  • 8
  • 28
  • This is really bad practice! Use `composer` for your dependencies. – ferdynator Nov 24 '14 at 12:51
  • 1
    Did you noticed that it was asked more than one year ago? IT WORKS means it does the job I know it's not fine... but by that time I had enough problems to make it work already and none else gave me any clue. Any way thank you but the job is done using the method you see and like that it's working for them... and the business is concluded. Maybe for version 2.0 I will add it. – Abel Nov 25 '14 at 08:11