public function preview($e)
 {
     $configName = $e['config'];
     $template = $e['template'];
     $layout = $e['layout'];
     $headers = empty($e['headers']) ? [] : (array) $e['headers'];
     $theme = empty($e['theme']) ? '' : (string) $e['theme'];
     $email = new Email($configName);
     if (!empty($e['attachments'])) {
         $email->attachments($e['attachments']);
     }
     $email->transport('Debug')->to($e['email'])->subject($e['subject'])->template($template, $layout)->emailFormat($e['format'])->addHeaders($headers)->theme($theme)->messageId(false)->returnPath($email->from())->viewVars($e['template_vars']);
     $return = $email->send();
     $this->out('Content:');
     $this->hr();
     $this->out($return['message']);
     $this->hr();
     $this->out('Headers:');
     $this->hr();
     $this->out($return['headers']);
     $this->hr();
     $this->out('Data:');
     $this->hr();
     debug($e['template_vars']);
     $this->hr();
     $this->out();
 }
 public function send($to, $variables = [], $options = [])
 {
     $result = false;
     if (!isset($options['transport'])) {
         $options['transport'] = $this->config('transport');
     }
     if (!isset($options['emailFormat'])) {
         $options['emailFormat'] = $this->config('emailFormat');
     }
     if (Configure::read('Email.queue')) {
         if (isset($options['from'])) {
             $options['from_name'] = reset($options['from']);
             $options['from_email'] = key($options['from']);
             unset($options['from']);
         }
         EmailQueue::enqueue($to, $variables, $options);
         $result = true;
     } else {
         $options['to'] = $to;
         $options['viewVars'] = $variables;
         $email = new Email();
         $email->profile($options);
         $result = $email->send();
     }
     return $result;
 }
示例#3
0
 protected function _execute(array $data)
 {
     $email = new Email('default');
     $email->from(['*****@*****.**' => 'EnTec 2016'])->emailFormat('html')->replyTo('*****@*****.**', 'EnTec 2016')->subject('[EntTec 2016] ' . $data['assunto']);
     $destinatarios = $data['destinatarios'];
     for ($i = 0, $c = count($destinatarios); $i < $c; $i++) {
         $email->addBcc($destinatarios[$i]['email'], $destinatarios[$i]['nome']);
     }
     $email->send($data['corpo']);
     return true;
 }
示例#4
0
 /**
  * Sends an email with a link that can be used in the next
  * 24 hours to give the user access to the password-reset page
  *
  * @param int $userId
  * @return boolean
  */
 public static function sendPasswordResetEmail($userId)
 {
     $timestamp = time();
     $hash = Mailer::getPasswordResetHash($userId, $timestamp);
     $resetUrl = Router::url(['prefix' => false, 'controller' => 'Users', 'action' => 'resetPassword', $userId, $timestamp, $hash], true);
     $email = new Email();
     $usersTable = TableRegistry::get('Users');
     $user = $usersTable->get($userId);
     $email->template('reset_password')->subject('MACC website password reset')->to($user->email)->viewVars(compact('user', 'resetUrl'));
     return $email->send();
 }
示例#5
0
 /**
  * mailer method
  *
  * @param array $data Dados para formar o email.
  * @return boolean True ou False.
  */
 public function mailer($data, $template, $subject)
 {
     $email = new Email();
     $email->transport('mailSgl');
     $email->emailFormat('html');
     $email->template($template);
     $email->from('*****@*****.**', 'SGL');
     $email->to($data['email'], $data['nome']);
     $email->viewVars($data);
     $email->subject($subject);
     $email->send();
 }
 /**
  * @param mixed $data Job data
  * @param int|null $id The id of the QueuedTask
  * @return bool Success
  */
 public function run(array $data, $id)
 {
     if (!isset($data['settings'])) {
         $this->err('Queue Email task called without settings data.');
         return false;
     }
     /* @var \Cake\Mailer\Email $email */
     $email = $data['settings'];
     if (is_object($email) && $email instanceof Email) {
         try {
             $transportClassNames = $email->configuredTransport();
             $result = $email->transport($transportClassNames[0])->send();
             if (!isset($config['log']) || !empty($config['logTrace']) && $config['logTrace'] === true) {
                 $config['log'] = 'email_trace';
             } elseif (!empty($config['logTrace'])) {
                 $config['log'] = $config['logTrace'];
             }
             if (isset($config['logTrace']) && !$config['logTrace']) {
                 $config['log'] = false;
             }
             if (!empty($config['logTrace'])) {
                 $this->_log($result, $config['log']);
             }
             return (bool) $result;
         } catch (Exception $e) {
             $error = $e->getMessage();
             $error .= ' (line ' . $e->getLine() . ' in ' . $e->getFile() . ')' . PHP_EOL . $e->getTraceAsString();
             Log::write('email_error', $error);
             return false;
         }
     }
     $class = 'Tools\\Mailer\\Email';
     if (!class_exists($class)) {
         $class = 'Cake\\Mailer\\Email';
     }
     $this->Email = new $class();
     $settings = array_merge($this->defaults, $data['settings']);
     foreach ($settings as $method => $setting) {
         call_user_func_array([$this->Email, $method], (array) $setting);
     }
     $message = null;
     if (!empty($data['vars'])) {
         if (isset($data['vars']['content'])) {
             $message = $data['vars']['content'];
         }
         $this->Email->viewVars($data['vars']);
     }
     return (bool) $this->Email->send($message);
 }
示例#7
0
 public function sendNewMissionsToInterestedUsers($nbrDays = 7)
 {
     $created = Time::now()->subDays($nbrDays);
     $missions = $this->Missions->find('all', ['conditions' => ['Missions.created >=' => $created]])->toArray();
     $newMissions = [];
     foreach ($missions as $mission) {
         $users = $this->Users->find('all')->toArray();
         foreach ($users as $user) {
             $usersTypeMissions = $this->UsersTypeMissions->findByUserId($user['id'])->toArray();
             foreach ($usersTypeMissions as $userTypeMissions) {
                 // Check if the current mission has the same type has the current userType mission
                 if ($userTypeMissions['type_mission_id'] == $mission['type_mission_id']) {
                     // Add a new mission to the list of missions to send
                     if (isset($newMissions[$user['email']])) {
                         $newMission = [];
                         $newMission['link'] = Router::url(['controller' => 'Missions', 'action' => 'view', $mission['id']]);
                         $newMission['name'] = $mission['name'];
                         //print("Mission " . $newMission['name'] . " added to user " . $user['email'] . "\n");
                         array_push($newMissions[$user['email']], $newMission);
                     } else {
                         //print("Creating mission list for user " . $user['email'] . "\n");
                         $newMissions[$user['email']] = [];
                         $newMission = [];
                         $newMission['link'] = Router::url(['controller' => 'Missions', 'action' => 'view', $mission['id']]);
                         $newMission['name'] = $mission['name'];
                         //print("Mission " . $newMission['name'] . " added to user " . $user['email'] . "\n");
                         array_push($newMissions[$user['email']], $newMission);
                     }
                 }
             }
         }
     }
     // For each user send their associated list of missions
     foreach ($newMissions as $userEmail => $missionsToSend) {
         $email = new Email();
         $email->domain('maisonlogiciellibre.org');
         $email->to($userEmail);
         $email->subject('New missions available at ML2');
         $email->template('new_missions');
         $email->emailFormat('both');
         $email->viewVars(['missions' => $missionsToSend]);
         $email->send();
     }
 }
 /**
  * Send notification
  *
  * @param \CvoTechnologies\Notifier\Notification $notification Notification instance.
  * @return array
  */
 public function send(Notification $notification)
 {
     $email = new Email();
     $email->profile($this->config('profile'));
     $email->to($notification->to(null, static::TYPE));
     $email->subject($notification->title());
     $email->viewBuilder()->templatePath($notification->viewBuilder()->templatePath());
     $email->viewBuilder()->template($notification->viewBuilder()->template());
     $email->viewBuilder()->plugin($notification->viewBuilder()->plugin());
     $email->viewBuilder()->theme($notification->viewBuilder()->theme());
     $email->viewBuilder()->layout($notification->viewBuilder()->layout());
     $email->viewBuilder()->autoLayout($notification->viewBuilder()->autoLayout());
     $email->viewBuilder()->layoutPath($notification->viewBuilder()->layoutPath());
     $email->viewBuilder()->name($notification->viewBuilder()->name());
     $email->viewBuilder()->className($notification->viewBuilder()->className());
     $email->viewBuilder()->options($notification->viewBuilder()->options());
     $email->viewBuilder()->helpers($notification->viewBuilder()->helpers());
     $email->viewVars($notification->viewVars());
     return $email->send();
 }
示例#9
0
 /**
  * @param mixed $charset
  * @param mixed $headerCharset
  * @return \Cake\Mailer\Email
  */
 protected function _getEmailByNewStyleCharset($charset, $headerCharset)
 {
     $email = new Email(['transport' => 'debug']);
     if (!empty($charset)) {
         $email->charset($charset);
     }
     if (!empty($headerCharset)) {
         $email->headerCharset($headerCharset);
     }
     $email->from('*****@*****.**', 'どこかの誰か');
     $email->to('*****@*****.**', 'どこかのどなたか');
     $email->cc('*****@*****.**', 'ミク');
     $email->subject('テストメール');
     $email->send('テストメールの本文');
     return $email;
 }
示例#10
0
 /**
  * Sends email.
  *
  * @param string $action The name of the mailer action to trigger.
  * @param array $args Arguments to pass to the triggered mailer action.
  * @param array $headers Headers to set.
  * @return array
  * @throws \Cake\Mailer\Exception\MissingActionException
  * @throws \BadMethodCallException
  */
 public function send($action, $args = [], $headers = [])
 {
     if (!method_exists($this, $action)) {
         throw new MissingActionException(['mailer' => $this->getName() . 'Mailer', 'action' => $action]);
     }
     $this->_email->setHeaders($headers);
     if (!$this->_email->viewBuilder()->template()) {
         $this->_email->viewBuilder()->template($action);
     }
     call_user_func_array([$this, $action], $args);
     $result = $this->_email->send();
     $this->reset();
     return $result;
 }
示例#11
0
 /**
  * Set the body of the mail as we send it.
  * Note: the text can be an array, each element will appear as a seperate line in the message body.
  *
  * Do NOT pass a message if you use $this->set() in combination with templates
  *
  * @override
  * @param string|array|null $message Message
  * @return bool Success
  */
 public function send($message = null)
 {
     $this->_log = ['to' => $this->_to, 'from' => $this->_from, 'sender' => $this->_sender, 'replyTo' => $this->_replyTo, 'cc' => $this->_cc, 'subject' => $this->_subject, 'bcc' => $this->_bcc, 'transport' => get_class($this->_transport)];
     if ($this->_priority) {
         $this->_headers['X-Priority'] = $this->_priority;
         //$this->_headers['X-MSMail-Priority'] = 'High';
         //$this->_headers['Importance'] = 'High';
     }
     // if not live, just log but do not send any mails //TODO: remove and use Debug Transport!
     if (!Configure::read('Config.live')) {
         $this->_logEmail();
         return true;
     }
     // Security measure to not sent to the actual addressee in debug mode while email sending is live
     if (Configure::read('debug') && Configure::read('Config.live')) {
         $adminEmail = Configure::read('Config.adminEmail');
         if (!$adminEmail) {
             $adminEmail = Configure::read('Config.systemEmail');
         }
         foreach ($this->_to as $k => $v) {
             if ($k === $adminEmail) {
                 continue;
             }
             unset($this->_to[$k]);
             $this->_to[$adminEmail] = $v;
         }
         foreach ($this->_cc as $k => $v) {
             if ($k === $adminEmail) {
                 continue;
             }
             unset($this->_cc[$k]);
             $this->_cc[$adminEmail] = $v;
         }
         foreach ($this->_bcc as $k => $v) {
             if ($k === $adminEmail) {
                 continue;
             }
             unset($this->_bcc[$k]);
             $this->_bcc[] = $v;
         }
     }
     try {
         $this->_debug = parent::send($message);
     } catch (\Exception $e) {
         $this->_error = $e->getMessage();
         $this->_error .= ' (line ' . $e->getLine() . ' in ' . $e->getFile() . ')' . PHP_EOL . $e->getTraceAsString();
         // always log report
         $this->_logEmail(LogLevel::ERROR);
         // log error
         $this->log($this->_error, LogLevel::ERROR);
         return false;
     }
     if (!empty($this->_profile['logReport'])) {
         $this->_logEmail();
     }
     return true;
 }
 /**
  * sendCalendarReminder method
  * Notification about the reminder is sent only
  * when the record belonds to anyone.
  * @param Cake\Event $event from the afterSave
  * @param Cake\Datasource\EntityInterface $entity from the afterSave
  * @return array|bool $sent on whether the email was sent
  */
 public function sendCalendarReminder(Event $event, EntityInterface $entity)
 {
     $sent = false;
     $currentUser = null;
     //get applications's timezone
     $timezone = Time::now()->format('e');
     $dtz = new \DateTimeZone($timezone);
     $table = $event->subject();
     //get attendees Table for the event
     if (method_exists($table, 'getConfig') && is_callable([$table, 'getConfig'])) {
         $config = $table->getConfig();
         $remindersTo = $table->getTableAllowRemindersField();
     }
     // skip if attendees Table is not defined
     if (empty($remindersTo)) {
         return $sent;
     }
     // Figure out which field is a reminder one
     $reminderField = $table->getReminderFields();
     if (empty($reminderField) || !is_array($reminderField)) {
         return $sent;
     }
     $reminderField = $reminderField[0];
     if (!is_array($reminderField) || empty($reminderField['name'])) {
         return $sent;
     }
     $reminderField = $reminderField['name'];
     // Skip sending email if reminder field is empty
     if (empty($entity->{$reminderField})) {
         return $sent;
     }
     $attendeesFields = $this->_getAttendeesFields($table, ['tables' => $remindersTo]);
     // skip if no attendees fields found
     if (empty($attendeesFields)) {
         return $sent;
     }
     // skip if none of the required fields was modified
     $requiredFields = array_merge((array) $reminderField, $attendeesFields);
     if (!$this->_requiredFieldsModified($entity, $requiredFields)) {
         return $sent;
     }
     /*
      * Figure out the subject of the email
      *
      * This should happen AFTER the `$table->getConfig()` call,
      * in case the display field of the table is changed from the
      * configuration.
      *
      * Use singular of the table name and the value of the entity's display field.
      * For example: "Call: Payment remind" or "Lead: Qobo Ltd".
      */
     $fhf = new FieldHandlerFactory();
     $emailSubjectValue = $fhf->renderValue($table, $table->displayField(), $entity->{$table->displayField()}, ['renderAs' => 'plain']);
     $eventSubject = $emailSubjectValue ?: 'reminder';
     $emailSubject = Inflector::singularize($table->alias()) . ": " . $eventSubject;
     $emailContent = Inflector::singularize($table->alias()) . " information was ";
     // If the record is being updated, prefix the above subject with "(Updated) ".
     if (!$entity->isNew()) {
         $emailSubject = '(Updated) ' . $emailSubject;
         $emailContent .= "updated";
     } else {
         $emailContent .= "created";
     }
     $emails = $this->_getAttendees($table, $entity, $attendeesFields);
     if (empty($emails)) {
         return $sent;
     }
     if (method_exists($table, 'getCurrentUser') && is_callable([$table, 'getCurrentUser'])) {
         $currentUser = $table->getCurrentUser();
         $emailContent .= " by " . $currentUser['email'];
     }
     // append changelog if entity is not new
     if (!$entity->isNew()) {
         $emailContent .= "\n\n" . $this->_getChangelog($entity);
     }
     foreach ($emails as $email) {
         $vCalendar = new \Eluceo\iCal\Component\Calendar('//EN//');
         $vAttendees = $this->_getEventAttendees($emails);
         $vEvent = $this->_getCalendarEvent($entity, ['dtz' => $dtz, 'organizer' => $email, 'subject' => $emailSubject, 'attendees' => $vAttendees, 'field' => $reminderField, 'timezone' => $timezone]);
         $vEvent->setAttendees($vAttendees);
         $vCalendar->addComponent($vEvent);
         $headers = "Content-Type: text/calendar; charset=utf-8";
         $headers .= 'Content-Disposition: attachment; filename="event.ics"';
         $emailer = new Email('default');
         $emailer->to($email)->setHeaders([$headers])->subject($emailSubject)->attachments(['event.ics' => ['contentDisposition' => true, 'mimetype' => 'text/calendar', 'data' => $vCalendar->render()]]);
         $sent = $emailer->send($emailContent);
     }
     return $sent;
 }
示例#13
0
 /**
  * sendmail method
  * Send Email using postmark addon
  * @param string|null $id Word id.
  * @return void
  * @throws \Cake\Network\Exception\NotFoundException When record not found.
  */
 public function sendmail($email, $subject, $mailText)
 {
     $mail = "mail";
     $loginuser = $this->Auth->user();
     $data = [];
     $data = ['mailFrom' => '*****@*****.**', 'email' => $email, 'mailSubject' => $subject, 'mailText' => $mailText];
     $email = new Email('default');
     $email->from(['*****@*****.**' => 'Word Master']);
     $email->to($data['email']);
     $email->subject($data['mailSubject']);
     $email->send($data['mailText']);
     $this->set('result', $data);
 }
示例#14
0
 /**
  * Register method
  *
  * @return void Redirects on successful add, renders view otherwise.
  *                     */
 public function register()
 {
     $this->viewBuilder()->layout('registerv2');
     $user = $this->Users->newEntity();
     if ($this->request->is('post')) {
         if ($this->Recaptcha->verify()) {
             $user = $this->Users->patchEntity($user, $this->request->data);
             $user->email_validation_code = rand(10000, 99999);
             $user->role = 'student';
             if ($this->Users->save($user)) {
                 $email = new Email();
                 $email->template('confirmation')->emailFormat('text')->to($user->email)->from('*****@*****.**');
                 $validate_url = "http://www.egresadositt.com/users/validateEmail/{$user->id}/{$user->email_validation_code}";
                 $email->viewVars(['first_name' => $user->first_name, 'email_validation_code' => $validate_url, 'user_name' => $user->username]);
                 $email->send();
                 $this->Flash->success(__('The user has been saved.'));
                 return $this->redirect(['controller' => 'Pages', 'action' => 'success']);
             } else {
                 $this->Flash->error(__('The user could not be saved. Please, try again.'));
             }
         } else {
             $this->Flash->error(__('Please check your Recaptcha Box.'));
         }
     }
     $generations = $this->Users->Generations->find('list', ['limit' => 200]);
     $careers = $this->Users->Careers->find('list', ['limit' => 200]);
     $questions = $this->Users->Questions->find('list', ['limit' => 200]);
     $this->set(compact('user', 'generations', 'careers', 'questions'));
     $this->set('_serialize', ['user']);
 }
 function forgot()
 {
     if ($this->request->is('post')) {
         $useremail = $this->request->data['user_email'];
         $check_user = $this->Users->find()->where(['user_email' => $this->request->data['user_email']]);
         $data = $check_user->toArray();
         if ($check_user->count() > 0) {
             $alphabet = "ABCDEFGHIJKLMNPQRSTUWXYZ123456789!@#\$";
             $pass = array();
             $alphaLength = strlen($alphabet) - 1;
             for ($i = 0; $i < 8; $i++) {
                 $n = rand(0, $alphaLength);
                 $pass[] = $alphabet[$n];
             }
             $user_pass = implode($pass);
             $email = new Email();
             $email->template('forgot')->emailFormat('html')->viewVars(['useremail' => $useremail, 'newpass' => $user_pass])->from(['*****@*****.**' => 'Ethos Watches'])->to($useremail)->subject('New Password for Eforce account');
             if ($email->send()) {
                 $user = $this->Users->get($data[0]->id);
                 $user->password = (new DefaultPasswordHasher())->hash($user_pass);
                 $this->Users->save($user);
                 $this->Flash->success(__('New password send on tour Email'));
             } else {
                 $this->Flash->error('Please try Again');
             }
         } else {
             //echo 'Email ID does not exists';
             $this->Flash->error('Email ID does not exists');
             //SessionComponent::setFlash('Email ID does not exists','flash_error');
         }
     }
     //$url = $this->request->data['url'];
     //$this->redirect(BASE_URL.$url);
 }