コード例 #1
0
ファイル: RealMailerTest.php プロジェクト: Konafets/oelib
 /**
  * @test
  */
 public function sendSendsEmail()
 {
     $senderAndRecipient = new Tx_Oelib_Tests_Unit_Fixtures_TestingMailRole('John Doe', '*****@*****.**');
     $eMail = new Tx_Oelib_Mail();
     $eMail->setSender($senderAndRecipient);
     $eMail->addRecipient($senderAndRecipient);
     $eMail->setSubject('Hello world!');
     $eMail->setMessage('Welcome!');
     $this->message->expects(self::once())->method('send');
     $this->subject->send($eMail);
 }
コード例 #2
0
ファイル: AbstractMailerTest.php プロジェクト: Konafets/oelib
 /**
  * @test
  */
 public function sendCanAddTwoAttachments()
 {
     $sender = new Tx_Oelib_Tests_Unit_Fixtures_TestingMailRole('', '*****@*****.**');
     $recipient = new Tx_Oelib_Tests_Unit_Fixtures_TestingMailRole('John Doe', $this->email['recipient']);
     $eMail = new Tx_Oelib_Mail();
     $eMail->setSender($sender);
     $eMail->addRecipient($recipient);
     $eMail->setSubject($this->email['subject']);
     $eMail->setMessage($this->email['message']);
     $attachment1 = new Tx_Oelib_Attachment();
     $attachment1->setFileName(t3lib_extMgm::extPath('oelib', 'Tests/Unit/Fixtures/test.txt'));
     $attachment1->setContentType('text/plain');
     $eMail->addAttachment($attachment1);
     $attachment2 = new Tx_Oelib_Attachment();
     $attachment2->setFileName(t3lib_extMgm::extPath('oelib', 'Tests/Unit/Fixtures/test_2.css'));
     $attachment2->setContentType('text/css');
     $eMail->addAttachment($attachment2);
     $this->subject->send($eMail);
     $children = $this->subject->getFirstSentEmail()->getChildren();
     self::assertSame(2, count($children));
 }
コード例 #3
0
ファイル: AbstractMailer.php プロジェクト: Konafets/oelib
 /**
  * Sends an Tx_Oelib_Mail object (one separate message per recipient).
  *
  * @param Tx_Oelib_Mail $email the Tx_Oelib_Mail object to send
  *
  * @return void
  *
  * @throws InvalidArgumentException
  */
 public function send(Tx_Oelib_Mail $email)
 {
     if (!$email->hasSender()) {
         throw new InvalidArgumentException('$email must have a sender set.', 1331318718);
     }
     $this->validateEmailAddress($email->getSender()->getEmailAddress(), 'From:');
     if ($email->getSubject() === '') {
         throw new InvalidArgumentException('The e-mail subject must not be empty.', 1409410879);
     }
     if (!$email->hasMessage()) {
         throw new InvalidArgumentException('The e-mail message must not be empty.', 1409410886);
     }
     $recipients = $email->getRecipients();
     if (empty($recipients)) {
         throw new InvalidArgumentException('The e-mail must have at least one recipient.', 1409410886);
     }
     foreach ($recipients as $recipient) {
         $this->validateEmailAddress($recipient->getEmailAddress(), 'To:');
     }
     /** @var t3lib_mail_Message $swiftMail */
     $swiftMail = t3lib_div::makeInstance('t3lib_mail_Message');
     $swiftMail->setSubject($email->getSubject());
     $sender = $email->getSender();
     $swiftMail->setFrom(array($sender->getEmailAddress() => $sender->getName()));
     $swiftMail->setCharset('utf-8');
     $returnPath = $email->getReturnPath();
     if ($returnPath !== '') {
         $swiftMail->setReturnPath($returnPath);
     }
     if ($email->hasMessage()) {
         $swiftMail->setBody($this->formatEmailBody($email->getMessage()));
     }
     if ($email->hasHTMLMessage()) {
         $swiftMail->addPart($email->getHTMLMessage(), 'text/html');
     }
     /** @var Tx_Oelib_Attachment $attachment */
     foreach ($email->getAttachments() as $attachment) {
         if ($attachment->getFileName() !== '' && $attachment->getContent() === '') {
             $swiftAttachment = Swift_Attachment::fromPath($attachment->getFileName(), $attachment->getContentType());
         } else {
             $fileName = $attachment->getFileName() !== '' ? $attachment->getFileName() : NULL;
             $swiftAttachment = Swift_Attachment::newInstance($attachment->getContent(), $fileName, $attachment->getContentType());
         }
         $swiftMail->attach($swiftAttachment);
     }
     foreach ($email->getRecipients() as $recipient) {
         $swiftMail->setTo(array($recipient->getEmailAddress() => $recipient->getName()));
         $this->sendSwiftMail($swiftMail);
     }
 }
コード例 #4
0
ファイル: MailTest.php プロジェクト: Konafets/oelib
 /**
  * @test
  */
 public function setReturnPathSetsMemberVariableReturnPath()
 {
     $this->subject->setReturnPath('*****@*****.**');
     self::assertSame('*****@*****.**', $this->subject->getReturnPath());
 }