AcMailer\Service\MailService::send PHP Method

send() public method

Sends the mail
public send ( ) : AcMailer\Result\ResultInterface
return AcMailer\Result\ResultInterface
    public function send()
    {
        $result = new MailResult();
        try {
            // Trigger pre send event
            $this->getEventManager()->triggerEvent($this->createMailEvent());
            // Attach files before sending the email
            $this->attachFiles();
            // Try to send the message
            $this->transport->send($this->message);
            // Trigger post send event
            $this->getEventManager()->triggerEvent($this->createMailEvent(MailEvent::EVENT_MAIL_POST_SEND, $result));
        } catch (\Exception $e) {
            $result = $this->createMailResultFromException($e);
            // Trigger send error event
            $this->getEventManager()->triggerEvent($this->createMailEvent(MailEvent::EVENT_MAIL_SEND_ERROR, $result));
            // If the exception produced is not a Zend\Mail exception, rethrow it as a MailException
            if (!$e instanceof ZendMailException) {
                throw new MailException('An non Zend\\Mail exception occurred', $e->getCode(), $e);
            }
        }
        return $result;
    }

Usage Example

 public function testStringBypassedBodyIsWrappedIntoMimePartWithAttachments()
 {
     $cwd = getcwd();
     chdir(dirname(__DIR__));
     $this->mailService->setAttachments(array('attachments/file1', 'attachments/file2'));
     $this->mailService->getMessage()->setBody('Btpassed body as string');
     $result = $this->mailService->send();
     $this->assertTrue($result->isValid());
     /* @var Mime\Message $body */
     $body = $this->mailService->getMessage()->getBody();
     $this->assertInstanceOf('Zend\\Mime\\Message', $body);
     chdir($cwd);
 }