Пример #1
0
 public function testSendMessage()
 {
     // Create an old email to purge
     Config::set('mail-tracker.expire-days', 1);
     $old_email = \jdavidbakr\MailTracker\Model\SentEmail::create(['hash' => str_random(32)]);
     $old_url = \jdavidbakr\MailTracker\Model\SentEmailUrlClicked::create(['sent_email_id' => $old_email->id, 'hash' => str_random(32)]);
     // Go into the future to make sure that the old email gets removed
     \Carbon\Carbon::setTestNow(\Carbon\Carbon::now()->addWeek());
     $faker = Faker\Factory::create();
     $email = $faker->email;
     $subject = $faker->sentence;
     $name = $faker->firstName . ' ' . $faker->lastName;
     \View::addLocation(__DIR__);
     \Mail::send('email.test', [], function ($message) use($email, $subject, $name) {
         $message->from('*****@*****.**', 'From Name');
         $message->sender('*****@*****.**', 'Sender Name');
         $message->to($email, $name);
         $message->cc('*****@*****.**', 'CC Name');
         $message->bcc('*****@*****.**', 'BCC Name');
         $message->replyTo('*****@*****.**', 'Reply-To Name');
         $message->subject($subject);
         $message->priority(3);
     });
     $this->seeInDatabase('sent_emails', ['recipient' => $name . ' <' . $email . '>', 'subject' => $subject, 'sender' => 'From Name <*****@*****.**>', 'recipient' => "{$name} <{$email}>"]);
     $this->assertNull($old_email->fresh());
     $this->assertNull($old_url->fresh());
 }
Пример #2
0
 /**
  * Inject the tracking code into the message
  */
 public function beforeSendPerformed(\Swift_Events_SendEvent $event)
 {
     $message = $event->getMessage();
     foreach ($message->getTo() as $to_email => $to_name) {
         foreach ($message->getFrom() as $from_email => $from_name) {
             $headers = $message->getHeaders();
             $hash = str_random(32);
             $headers->addTextHeader('X-Mailer-Hash', $hash);
             $subject = $message->getSubject();
             $original_content = $message->getBody();
             if ($message->getContentType() === 'text/html' || $message->getContentType() === 'multipart/alternative' && $message->getBody()) {
                 $message->setBody($this->addTrackers($message->getBody(), $hash));
             }
             foreach ($message->getChildren() as $part) {
                 if (strpos($part->getContentType(), 'text/html') === 0) {
                     $converter->setHTML($part->getBody());
                     $part->setBody($this->addTrackers($message->getBody(), $hash));
                 }
             }
             SentEmail::create(['hash' => $hash, 'headers' => $headers->toString(), 'sender' => $from_name . " <" . $from_email . ">", 'recipient' => $to_name . ' <' . $to_email . '>', 'subject' => $subject, 'content' => $original_content, 'opens' => 0, 'clicks' => 0, 'message_id' => $message->getId(), 'meta' => []]);
         }
     }
     // Purge old records
     if (config('mail-tracker.expire-days') > 0) {
         $emails = SentEmail::where('created_at', '<', \Carbon\Carbon::now()->subDays(config('mail-tracker.expire-days')))->select('id')->get();
         SentEmailUrlClicked::whereIn('sent_email_id', $emails->pluck('id'))->delete();
         SentEmail::whereIn('id', $emails->pluck('id'))->delete();
     }
 }
Пример #3
0
 /**
  * Url Detail.
  *
  * @return \Illuminate\Http\Response
  */
 public function getUrlDetail($id)
 {
     $detalle = SentEmailUrlClicked::where('sent_email_id', $id)->get();
     if (!$detalle) {
         return back();
     }
     return \View('emailTrakingViews::url_detail')->with('details', $detalle);
 }
 public function getL($url, $hash)
 {
     $url = base64_decode(str_replace("\$", "/", $url));
     $tracker = Model\SentEmail::where('hash', $hash)->first();
     if ($tracker) {
         $tracker->clicks++;
         $tracker->save();
         $url_clicked = Model\SentEmailUrlClicked::where('url', $url)->where('hash', $hash)->first();
         if ($url_clicked) {
             $url_clicked->clicks++;
             $url_clicked->save();
         } else {
             $url_clicked = Model\SentEmailUrlClicked::create(['sent_email_id' => $tracker->id, 'url' => $url, 'hash' => $tracker->hash]);
         }
         Event::fire(new LinkClickedEvent($tracker));
     }
     return redirect($url);
 }