/**
  * Send a notification to one user
  *
  * @param string $userName Username of the recipient
  * @param string $email Email address of the recipient
  * @param string $lang Selected language of the recipient
  * @param string $timezone Selected timezone of the recipient
  * @param int $maxTime
  */
 public function sendEmailToUser($userName, $email, $lang, $timezone, $maxTime)
 {
     $user = $this->userManager->get($userName);
     if (!$user instanceof IUser) {
         return;
     }
     list($mailData, $skippedCount) = $this->getItemsForUser($userName, $maxTime);
     $l = $this->getLanguage($lang);
     $this->dataHelper->setUser($userName);
     $this->dataHelper->setL10n($l);
     $activityList = array();
     foreach ($mailData as $activity) {
         $relativeDateTime = $this->dateFormatter->formatDateTimeRelativeDay($activity['amq_timestamp'], 'long', 'medium', new \DateTimeZone($timezone), $l);
         $activityList[] = array($this->dataHelper->translation($activity['amq_appid'], $activity['amq_subject'], $this->dataHelper->getParameters($activity['amq_subjectparams'])), $relativeDateTime);
     }
     $alttext = new Template('activity', 'email.notification', '');
     $alttext->assign('username', $user->getDisplayName());
     $alttext->assign('activities', $activityList);
     $alttext->assign('skippedCount', $skippedCount);
     $alttext->assign('owncloud_installation', $this->urlGenerator->getAbsoluteURL('/'));
     $alttext->assign('overwriteL10N', $l);
     $emailText = $alttext->fetchPage();
     $message = $this->mailer->createMessage();
     $message->setTo([$email => $user->getDisplayName()]);
     $message->setSubject((string) $l->t('Activity notification'));
     $message->setPlainBody($emailText);
     $message->setFrom([$this->getSenderData('email') => $this->getSenderData('name')]);
     $this->mailer->send($message);
 }
 /**
  * Send a notification to one user
  *
  * @param string $user Username of the recipient
  * @param string $email Email address of the recipient
  * @param string $lang Selected language of the recipient
  * @param string $timezone Selected timezone of the recipient
  * @param array $mailData Notification data we send to the user
  */
 public function sendEmailToUser($user, $email, $lang, $timezone, $mailData)
 {
     $l = $this->getLanguage($lang);
     $dataHelper = new DataHelper(\OC::$server->getActivityManager(), new ParameterHelper(\OC::$server->getActivityManager(), new \OC\Files\View(''), \OC::$server->getConfig(), $l), $l);
     $activityList = array();
     foreach ($mailData as $activity) {
         $relativeDateTime = $this->dateFormatter->formatDateTimeRelativeDay($activity['amq_timestamp'], 'long', 'medium', new \DateTimeZone($timezone), $l);
         $activityList[] = array($dataHelper->translation($activity['amq_appid'], $activity['amq_subject'], unserialize($activity['amq_subjectparams'])), $relativeDateTime);
     }
     $alttext = new \OCP\Template('activity', 'email.notification', '');
     $alttext->assign('username', \OCP\User::getDisplayName($user));
     $alttext->assign('timeframe', $this->getLangForApproximatedTimeFrame($mailData[0]['amq_timestamp']));
     $alttext->assign('activities', $activityList);
     $alttext->assign('owncloud_installation', \OC_Helper::makeURLAbsolute('/'));
     $alttext->assign('overwriteL10N', $l);
     $emailText = $alttext->fetchPage();
     try {
         \OCP\Util::sendMail($email, \OCP\User::getDisplayName($user), $l->t('Activity notification'), $emailText, $this->getSenderData('email'), $this->getSenderData('name'));
     } catch (\Exception $e) {
         \OCP\Util::writeLog('Activity', 'A problem occurred while sending the e-mail. Please revisit your settings.', \OCP\Util::ERROR);
     }
 }