protected function _createMail(UserModel $user, $brand = null) { if (\App::get('mail') === null) { throw new UnexpectedException('No mail transport configured'); } $fullName = $user->getFirstName() . ' ' . $user->getLastName(); // Creating / configuring email object. $mail = new \App_Mail('UTF-8'); $mail->setLocale($user->getLanguage()); $mail->addTo($user->getEmail(), $fullName); $view = $mail->getView(); $view->fullName = $fullName; $view->userName = $user->userName; $view->user = $user; // Configure brand mail folder if (!$brand || !$brand instanceof BrandModel) { $brandService = BrandService::getInstance(); $brand = $brandService->loadByUser($user); } if (!$brand || !$brand instanceof BrandModel) { throw new NotFoundException("Brand not found for user " . $user->id); } $mail->setScriptNamespace($brand->getScriptNamespace()); $view->setBaseUrl($brand->getEndPoint()); $view->setImageNamespace($brand->getImageNamespace()); $view->brand = $brand; \App::log()->debug("Sending an email using '" . $brand->brand . "' brand"); return $mail; }