Esempio n. 1
0
 /**
  *
  * Mauro Cerone
  *
  * @param Email $email        	
  * @todo implement the attachment (path to file, or database blob)
  */
 public static function addMailToSend(Email $email)
 {
     if (!empty($email->getStringA())) {
         $newMail = new StesiMail();
         $newMail->setFrom($email->getFrom()->getAddress())->setA($email->getStringA())->setCc($email->getStringCc())->setContent($email->getTemplate()->getHtml())->setSubject($email->getSubject());
         $newMail->save();
     }
 }
Esempio n. 2
0
 /**
  * Tests the `setSubject` method.
  *
  * @return void
  * @access public
  */
 public function testSetSubject()
 {
     $this->assertIdentical($this->_object->getSubject(), '');
     // Make sure the setting was successful.
     $this->_object->setSubject('Test');
     $this->assertIdentical($this->_object->getSubject(), 'Test');
     // We only allow strings to be passed in.
     $this->expectException();
     $this->_object->setSubject(new Object());
 }
Esempio n. 3
0
 /**
  * Performs a Google Analytics query with the given Google\Analytics\IQuery
  * object and attaches the result to the given Email instance. If the email
  * does not yet have a subject, one will be set automatically. If failures
  * took place while running the query (e.g. the query declared a preference
  * for no data sampling and one or more iterations contained sampled data),
  * a message regarding the failure will be appended to the email
  * automatically. If a file path is provided as the fourth argument, the
  * report will be copied to that location in addition to being attached to
  * the email.
  *
  * @param Google\Analytics\IQuery $query
  * @param Google\Analytics\ReportFormatter $formatter
  * @param Email $email
  * @param string $file = null
  */
 public function queryToEmail(IQuery $query, ReportFormatter $formatter, \Email $email, $file = null)
 {
     if ($file && !\PFXUtils::testWritable(dirname($file))) {
         throw new RuntimeException('Cannot write to ' . $file . '.');
     }
     $hasSubject = strlen($email->getSubject()) > 0;
     try {
         $formatter->openTempFile(GOOGLE_ANALYTICS_API_DATA_DIR);
         $exception = null;
         try {
             $this->queryToFile($query, $formatter);
         } catch (FailedIterationsException $e) {
             /* Trap this exception here for now and deliver whatever data
                we can. */
             $exception = $e;
         }
         $bytesWritten = $formatter->getBytesWritten();
         if ($bytesWritten) {
             $tempFile = $formatter->getFileName();
             if ($bytesWritten > GOOGLE_ANALYTICS_API_AUTOZIP_THRESHOLD) {
                 $zip = new \ZipArchive();
                 $tempZip = tempnam(GOOGLE_ANALYTICS_API_DATA_DIR, 'gaz');
                 if ($zip->open($tempZip, \ZipArchive::CREATE) !== true) {
                     throw new RuntimeException('Failed to initialize ZIP archive. Did not ' . 'include the file ' . basename($tempFile) . ' in this message due to its size exceeding ' . GOOGLE_ANALYTICS_API_AUTOZIP_THRESHOLD . ' bytes.');
                 }
                 $zip->addFile($tempFile, 'ga-report.csv');
                 $zip->close();
                 $email->addAttachment($tempZip, 'ga-report.zip');
                 unlink($tempZip);
             } else {
                 $email->addAttachment($tempFile, 'ga-report.csv');
             }
             if ($file && !copy($tempFile, $file)) {
                 throw new RuntimeException('Unable to copy report to ' . $file . '.');
             }
             unlink($tempFile);
         }
         if (!$hasSubject) {
             $email->setSubject($query->getEmailSubject());
             $hasSubject = true;
         }
         if ($exception) {
             throw $exception;
         } elseif (!$bytesWritten) {
             throw new UnderflowException('Google returned no data for this query.');
         }
     } catch (\Exception $e) {
         if (!$hasSubject) {
             /* This should only happen if there is an error affecting the
                report as a whole, not just in one or more of its iterations.
                */
             $email->setSubject('Encountered failure while running ' . $query->getEmailSubject());
         }
         $email->appendMessage($e->getMessage(), true);
     }
 }
Esempio n. 4
0
 /**
  * Runs the test.
  */
 public function test()
 {
     $filePath = DIR_FILES . '/mail';
     $subject = 'Novinky září 2009 ... a kreslící soutěž';
     $from = new Email\Address('*****@*****.**', 'Blog.cz');
     $to = array(new Email\Address('*****@*****.**', 'Test Test1'), new Email\Address('*****@*****.**'));
     $cc = array(new Email\Address('*****@*****.**', 'Test Test3'), new Email\Address('*****@*****.**'));
     $bcc = array(new Email\Address('*****@*****.**', 'Test Test5'));
     $headers = array(new Email\Header('Organization', 'Blog.cz'));
     $inReplyTo = '*****@*****.**';
     $references = array('*****@*****.**', '*****@*****.**');
     $html = file_get_contents($filePath . '/email.html');
     $body = new Email\Body($html, \Jyxo\Html::toText($html));
     $attachments = array(new Email\Attachment\File($filePath . '/logo.gif', 'logo.gif', 'image/gif'), new Email\Attachment\String(file_get_contents($filePath . '/star.gif'), 'star.gif', 'image/gif'));
     $inlineAttachments = array(new Email\Attachment\InlineFile($filePath . '/logo.gif', 'logo.gif', 'logo.gif', 'image/gif'), new Email\Attachment\InlineString(file_get_contents($filePath . '/star.gif'), 'star.gif', 'star.gif', 'image/gif'));
     // Basic settings
     $email = new Email();
     $email->setSubject($subject)->setFrom($from)->addReplyTo($from)->setInReplyTo($inReplyTo, $references)->setConfirmReadingTo($from);
     $this->assertEquals($subject, $email->getSubject());
     $this->assertSame($from, $email->getFrom());
     $this->assertSame(array($from), $email->getReplyTo());
     $this->assertSame($from, $email->getConfirmReadingTo());
     $this->assertEquals($inReplyTo, $email->getInReplyTo());
     $this->assertSame($references, $email->getReferences());
     // Recipients
     foreach ($to as $address) {
         $email->addTo($address);
     }
     foreach ($cc as $address) {
         $email->addCc($address);
     }
     foreach ($bcc as $address) {
         $email->addBcc($address);
     }
     $this->assertSame($to, $email->getTo());
     $this->assertSame($cc, $email->getCc());
     $this->assertSame($bcc, $email->getBcc());
     // Priority
     $reflection = new \ReflectionClass('\\Jyxo\\Mail\\Email');
     foreach ($reflection->getConstants() as $name => $value) {
         if (0 === strpos($name, 'PRIORITY_')) {
             $email->setPriority($value);
             $this->assertEquals($value, $email->getPriority());
         }
     }
     try {
         $email->setPriority('dummy-priority');
         $this->fail('Expected exception \\InvalidArgumentException.');
     } catch (\PHPUnit_Framework_AssertionFailedError $e) {
         throw $e;
     } catch (\Exception $e) {
         // Correctly thrown exception
         $this->assertInstanceOf('\\InvalidArgumentException', $e);
     }
     // Headers
     foreach ($headers as $header) {
         $email->addHeader($header);
     }
     $this->assertSame($headers, $email->getHeaders());
     // Body
     $email->setBody($body);
     $this->assertSame($body, $email->getBody());
     // Attachments
     foreach ($attachments as $attachment) {
         $email->addAttachment($attachment);
     }
     $this->assertSame($attachments, $email->getAttachments());
     $this->assertFalse($email->hasInlineAttachments());
     foreach ($inlineAttachments as $attachment) {
         $email->addAttachment($attachment);
     }
     $this->assertSame(array_merge($attachments, $inlineAttachments), $email->getAttachments());
     $this->assertTrue($email->hasInlineAttachments());
 }
Esempio n. 5
0
 /**
  *
  */
 public function testConstructSubject()
 {
     $email = new Email('*****@*****.**', 'subject', 'hello you');
     $this->assertEquals('subject', $email->getSubject());
 }
Esempio n. 6
0
 function test_setSubject()
 {
     //Arrange
     $name = "Bill";
     $email = "*****@*****.**";
     $subject = "Just saying hi";
     $message = "Hello to you good sir";
     $notarobot = "123";
     $test_email = new Email($name, $email, $subject, $message, $notarobot);
     //Act
     $new_subject = "Just saying hi, again";
     $test_email->setSubject($new_subject);
     $result = $test_email->getSubject();
     //Assert
     $this->assertEquals("Just saying hi, again", $result);
 }
 public function sendEmail(Email $email)
 {
     mail($email->getRecipientList(), $email->getSubject(), $email->getBodyRaw(), $email->getMailHeadersAsString());
 }
 protected function _mapToSwift(Email $email)
 {
     $message = new \Swift_Message($email->getSubject());
     /*
      * Since we're sending transactional email, we want the message to go to one person at a time, rather
      * than a bulk send on one message. In order to do this, we'll have to send the list of recipients through the headers
      * but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be 
      * ignored anyway.
      */
     $message->setTo($email->getFrom());
     $message->setFrom($email->getFrom(true));
     $message->setCc($email->getCcs());
     $message->setBcc($email->getBccs());
     if ($email->getHtml()) {
         $message->setBody($email->getHtml(), 'text/html');
         if ($email->getText()) {
             $message->addPart($email->getText(), 'text/plain');
         }
     } else {
         $message->setBody($email->getText(), 'text/plain');
     }
     if ($replyto = $email->getReplyTo()) {
         $message->setReplyTo($replyto);
     }
     // determine whether or not we can use SMTP recipients (non header based)
     if ($email->useHeaders()) {
         //send header based email
         $message->setTo($email->getFrom());
         //here we'll add the recipients list to the headers
         $headers = $email->getSmtpapiHeaders();
         $headers['to'] = $email->getTos();
         $email->setSmtpapiHeaders($headers);
     } else {
         $recipients = array();
         foreach ($email->getTos() as $recipient) {
             if (preg_match("/(.*)<(.*)>/", $recipient, $results)) {
                 $recipients[trim($results[2])] = trim($results[1]);
             } else {
                 $recipients[] = $recipient;
             }
         }
         $message->setTo($recipients);
     }
     $attachments = $email->getAttachments();
     //add any attachments that were added
     if ($attachments) {
         foreach ($attachments as $attachment) {
             if (array_key_exists('custom_filename', $attachment)) {
                 $message->attach(\Swift_Attachment::fromPath($attachment['file'])->setFileName($attachment['custom_filename']));
             } else {
                 $message->attach(\Swift_Attachment::fromPath($attachment['file']));
             }
         }
     }
     //add all the headers
     $headers = $message->getHeaders();
     $headers->addTextHeader('X-SMTPAPI', $email->getSmtpapiHeadersJson());
     // Add the extra message headers (RFC 822)
     if (count($email->getMessageHeaders())) {
         foreach ($email->getMessageHeaders() as $name => $value) {
             $headers->addTextHeader($name, $value);
         }
     }
     return $message;
 }