MailSender in Controller

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • item
    Active Community Member
    • Mar 2017
    • 1478

    MailSender in Controller

    Hi,
    I will send a email in a controller, but receive :

    Call to undefined method Espo\\Custom\\Controllers\\Contact::getMailSender( ) at custom/Espo/Custom/Controllers/Contact.php

    It's certainly easy .. but I lag

    Regards

    PHP Code:
    namespace Espo\Custom\Controllers;
    
    use \Espo\ORM\Entity;
    use \Espo\Entities;
    use \Espo\Core\Utils\Util;
    use \Espo\Entities\Email;
    
    
    class Contact extends \Espo\Core\Templates\Controllers\Person
    {
            $email = $this->getEntityManager()->getEntity('Email');
            $email->set([
                'to' => 'to@mailsender.net',
                'subject' => 'subject',
                'body' => 'body',
                'isHtml' => false
            ]);
    
            $this->getMailSender()->send($email);
    
            return true;
    } 
    


    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​
  • tanya
    Senior Member
    • Jun 2014
    • 4308

    #2
    Hi,
    you need to define this method, like here https://github.com/espocrm/espocrm/b...sEmail.php#L57
    but better do it in Service, not in controller.

    Comment

    • item
      Active Community Member
      • Mar 2017
      • 1478

      #3
      Hi Tanya,
      I have try but not understand .. what is "service" ?
      Yes I see in directory, in file, in documentation about workflow .. what is the "role" of service ? when need that ?
      Hook, Controller.. it's ok for me.. but service .. if you can a little explain ..
      Regards
      If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

      Comment

      • tanya
        Senior Member
        • Jun 2014
        • 4308

        #4
        Hello,
        in general controllers in EspoCRM is used for ACL check (permissions) and call service method
        Hi, I was doing some code additions in the EspoCRM\application\Espo\Modules\Crm\Services\Account.php. From all I see I am pretty sure that if there is an

        btw, in your controller I can't find any method...

        Comment

        Working...