Ejemplo n.º 1
0
 public function main()
 {
     $this->loadModel('Comms');
     $comms = $this->Comms->find('all')->select(['Comms.id', 'Comms.dest', 'Comms.subject', 'Comms.body', 'Users.email'])->contain('Users')->where(['OR' => [['comms_status_id' => COMM_NEW], ['comms_status_id' => 0]]])->limit(10)->toArray();
     foreach ($comms as $comm) {
         //TODO: correct this unreliable and inflexible way to send emails
         Email::deliver(COMPANY_EMAIL, $comm->subject, $comm->body, ['from' => $comm->user->email, 'transport' => 'default', 'domain' => WEBSITE_DOMAIN]);
         $this->Comms->patchEntity($comm, ['comms_status_id' => COMM_COMPLETED]);
         $this->Comms->save($comm);
     }
 }
Ejemplo n.º 2
0
 /**
  * testDeliver method
  *
  * @return void
  */
 public function testDeliver()
 {
     $instance = Email::deliver('*****@*****.**', 'About', 'Everything ok', array('from' => '*****@*****.**'), false);
     $this->assertInstanceOf('Cake\\Network\\Email\\Email', $instance);
     $this->assertSame($instance->to(), array('*****@*****.**' => '*****@*****.**'));
     $this->assertSame($instance->subject(), 'About');
     $this->assertSame($instance->from(), array('*****@*****.**' => '*****@*****.**'));
     $config = array('from' => '*****@*****.**', 'to' => '*****@*****.**', 'subject' => 'Update ok', 'template' => 'custom', 'layout' => 'custom_layout', 'viewVars' => array('value' => 123), 'cc' => array('*****@*****.**' => 'Myself'));
     $instance = Email::deliver(null, null, array('name' => 'CakePHP'), $config, false);
     $this->assertSame($instance->from(), array('*****@*****.**' => '*****@*****.**'));
     $this->assertSame($instance->to(), array('*****@*****.**' => '*****@*****.**'));
     $this->assertSame($instance->subject(), 'Update ok');
     $this->assertSame($instance->template(), array('template' => 'custom', 'layout' => 'custom_layout'));
     $this->assertSame($instance->viewVars(), array('value' => 123, 'name' => 'CakePHP'));
     $this->assertSame($instance->cc(), array('*****@*****.**' => 'Myself'));
     $configs = array('from' => '*****@*****.**', 'message' => 'Message from configs', 'transport' => 'debug');
     $instance = Email::deliver('*****@*****.**', 'About', null, $configs, true);
     $message = $instance->message();
     $this->assertEquals($configs['message'], $message[0]);
 }
Ejemplo n.º 3
0
 /**
  * Reset user's password
  *
  * @param App\Model\Entity\User $user User
  * @return void
  */
 protected function resetPassword($user)
 {
     // primitive way to generate temporary password
     $user->password = $password = substr(sha1(time() . rand() . Configure::read('Security.salt')), 0, 8);
     $this->Users->save($user);
     Email::deliver($user->email, "New notejam password", "Your new temporary password is {$password}.\n             We recommend you to change it after signing in.", ["from" => "*****@*****.**", "transport" => "default"]);
 }