/** * Process send email message. In case exist custom smtp host/port use it * * @param \Swift_Message $message * @param UserEmailOrigin $emailOrigin * @throws \Swift_SwiftException */ public function processSend($message, $emailOrigin) { if ($emailOrigin instanceof UserEmailOrigin) { /* Modify transport smtp settings */ if ($emailOrigin->isSmtpConfigured()) { $this->mailer->prepareSmtpTransport($emailOrigin); } } if (!$this->mailer->send($message)) { throw new \Swift_SwiftException('An email was not delivered.'); } }
/** * @expectedException \Exception */ public function testSendWithException() { $message = new \Swift_Message(); $failedRecipients = array(); $transport = $this->getMock('\\Swift_Transport'); $this->baseMailer->expects($this->once())->method('getTransport')->will($this->returnValue($transport)); $this->container->expects($this->never())->method('getParameter'); $transport->expects($this->at(0))->method('isStarted')->will($this->returnValue(false)); $transport->expects($this->once())->method('start'); $transport->expects($this->at(2))->method('isStarted')->will($this->returnValue(true)); $transport->expects($this->once())->method('send')->with($this->identicalTo($message), $this->identicalTo($failedRecipients))->will($this->throwException(new \Exception('test failure'))); $transport->expects($this->once())->method('stop'); $mailer = new DirectMailer($this->baseMailer, $this->container); $this->assertEquals(1, $mailer->send($message, $failedRecipients)); }
public function testSendWithSmtpConfigured() { $message = new \Swift_Message(); $failedRecipients = array(); $transport = $this->getMock('\\Swift_SmtpTransport'); $this->baseMailer->expects($this->once())->method('getTransport')->will($this->returnValue($transport)); $this->container->expects($this->never())->method('getParameter'); $transport->expects($this->at(0))->method('isStarted')->will($this->returnValue(false)); $transport->expects($this->once())->method('start'); $transport->expects($this->at(2))->method('isStarted')->will($this->returnValue(true)); $transport->expects($this->once())->method('send')->with($this->identicalTo($message), $this->identicalTo($failedRecipients))->will($this->returnValue(1)); $transport->expects($this->once())->method('stop'); $encoder = $this->getMock('Oro\\Bundle\\SecurityBundle\\Encoder\\Mcrypt'); $this->container->expects($this->any())->method('get')->with($this->equalTo('oro_security.encoder.mcrypt'))->will($this->returnValue($encoder)); $mailer = new DirectMailer($this->baseMailer, $this->container, $this->imapEmailGoogleOauth2Manager); $transport->expects($this->once())->method('setHost'); $transport->expects($this->once())->method('setPort'); $mailer->prepareSmtpTransport($this->userEmailOrigin); $this->assertEquals(1, $mailer->send($message, $failedRecipients)); }