/** * @param Notification $notification * @param TaskNotificationRules $rule * @param string $action * @return EmailMessage */ protected static function makeEmailMessage(Notification $notification, TaskNotificationRules $rule, $action) { assert('is_string($action)'); $emailMessage = new EmailMessage(); $emailMessage->owner = Yii::app()->user->userModel; $task = $rule->getModel(); $emailMessage->subject = static::getTaskEmailSubject($task, $action); return $emailMessage; }
/** * Send task email * @param Notification $notification * @param TaskNotificationRules $rule * @param string $action */ protected static function sendTaskEmail(Notification $notification, TaskNotificationRules $rule, $action) { assert('is_string($action)'); $notificationSettingName = static::resolveNotificationSettingNameFromType($rule->getType()); if ($notification->owner->primaryEmail->emailAddress !== null && UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($notification->owner, $notificationSettingName, 'email')) { $emailMessage = static::makeEmailMessage(); $emailMessage->subject = static::getEmailSubject($notification, $rule); $emailMessage->content = static::makeEmailContent($notification); $emailMessage->sender = static::makeSender(); $emailMessage->recipients->add(static::makeRecipient($notification)); $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME); $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT); try { Yii::app()->emailHelper->send($emailMessage); } catch (CException $e) { //Not sure what to do yet when catching an exception here. Currently ignoring gracefully. } } }