public function testResolveNotificationTextTemplate() { $bodyContent = 'test my body'; $resolvedContent = EmailNotificationUtil::resolveNotificationTextTemplate($bodyContent); $this->assertContains($bodyContent, $resolvedContent); $this->assertContains('Manage your email preferences:', $resolvedContent); $this->assertContains('Powered By Zurmo' . PHP_EOL . 'http://www.zurmo.com', $resolvedContent); }
public static function getEmailContent(RedBeanModel $model, Comment $comment, User $user) { $emailContent = new EmailMessageContent(); $url = static::getUrlToEmail($model); $textContent = Zurmo::t('CommentsModule', "Hello, {lineBreak} {updaterName} added a new comment to the " . "{strongStartTag}{modelName}{strongEndTag}: {lineBreak}" . "\"{commentDescription}.\" {lineBreak}{lineBreak} {url} ", array('{lineBreak}' => "\n", '{strongStartTag}' => null, '{strongEndTag}' => null, '{updaterName}' => strval($user), '{modelName}' => $model->getModelLabelByTypeAndLanguage('SingularLowerCase'), '{commentDescription}' => strval($comment), '{url}' => ZurmoHtml::link($url, $url))); $emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate($textContent); $htmlContent = Zurmo::t('CommentsModule', "Hello, {lineBreak} {updaterName} added a new comment to the " . "{strongStartTag}{url}{strongEndTag}: {lineBreak}" . "\"{commentDescription}.\"", array('{lineBreak}' => "<br/>", '{strongStartTag}' => '<strong>', '{strongEndTag}' => '</strong>', '{updaterName}' => strval($user), '{commentDescription}' => strval($comment), '{url}' => ZurmoHtml::link($model->getModelLabelByTypeAndLanguage('SingularLowerCase'), $url))); $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate($htmlContent); return $emailContent; }
/** * Send a test email. * $from('name' => 'fromName', 'address' => 'fromAddress') * @param EmailHelper $emailHelper * @param Array $from * @param string $toAddress */ public static function sendTestEmail(EmailHelper $emailHelper, array $from, $toAddress) { assert('is_string($from["name"])'); assert('is_string($from["address"])'); $emailMessage = new EmailMessage(); $emailMessage->owner = Yii::app()->user->userModel; $emailMessage->subject = Zurmo::t('EmailMessagesModule', 'A test email from Zurmo', LabelUtil::getTranslationParamsForAllModules()); $emailContent = new EmailMessageContent(); $emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate(Zurmo::t('EmailMessagesModule', 'A test text message from Zurmo.', LabelUtil::getTranslationParamsForAllModules())); $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate(Zurmo::t('EmailMessagesModule', 'A test text message from Zurmo.', LabelUtil::getTranslationParamsForAllModules())); $emailMessage->content = $emailContent; $sender = new EmailMessageSender(); $sender->fromAddress = $from['address']; $sender->fromName = $from['name']; $emailMessage->sender = $sender; $recipient = new EmailMessageRecipient(); $recipient->toAddress = $toAddress; $recipient->toName = 'Test Recipient'; $recipient->type = EmailMessageRecipient::TYPE_TO; $emailMessage->recipients->add($recipient); $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME); $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT); $validated = $emailMessage->validate(); if ($validated) { $emailHelper->sendImmediately($emailMessage); } return $emailMessage; }
/** * @param Conversation $conversation * @param $person */ public static function sendEmailInviteToParticipant(Conversation $conversation, $person) { assert('$conversation->id > 0'); assert('$person instanceof User || $person instanceof Contact'); if ($person->primaryEmail->emailAddress !== null) { $userToSendMessagesFrom = $conversation->owner; $emailMessage = new EmailMessage(); $emailMessage->owner = Yii::app()->user->userModel; $emailMessage->subject = Zurmo::t('ConversationsModule', 'You have been invited to participate in a conversation'); $emailContent = new EmailMessageContent(); $emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate(static::getParticipantInviteEmailTextContent($conversation)); $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate(static::getParticipantInviteEmailHtmlContent($conversation)); $emailMessage->content = $emailContent; $sender = new EmailMessageSender(); $sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom); $sender->fromName = strval($userToSendMessagesFrom); $sender->personsOrAccounts->add($userToSendMessagesFrom); $emailMessage->sender = $sender; $recipient = new EmailMessageRecipient(); $recipient->toAddress = $person->primaryEmail->emailAddress; $recipient->toName = strval($person); $recipient->type = EmailMessageRecipient::TYPE_TO; $recipient->personsOrAccounts->add($person); $emailMessage->recipients->add($recipient); $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. } } }
/** * @param Notification $notification * @return EmailMessageContent */ protected static function makeEmailContent(Notification $notification) { $emailContent = new EmailMessageContent(); $emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate($notification->notificationMessage->textContent, $notification->owner); $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate($notification->notificationMessage->htmlContent, $notification->owner); return $emailContent; }
protected static function sendEmail(Notification $notification) { if ($notification->owner->primaryEmail->emailAddress !== null && !UserConfigurationFormAdapter::resolveAndGetValue($notification->owner, 'turnOffEmailNotifications')) { $userToSendMessagesFrom = BaseControlUserConfigUtil::getUserToRunAs(); $emailMessage = new EmailMessage(); $emailMessage->owner = Yii::app()->user->userModel; $emailMessage->subject = strval($notification); $emailContent = new EmailMessageContent(); $emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate($notification->notificationMessage->textContent); $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate($notification->notificationMessage->htmlContent); $emailMessage->content = $emailContent; $sender = new EmailMessageSender(); $sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom); $sender->fromName = strval($userToSendMessagesFrom); $emailMessage->sender = $sender; $recipient = new EmailMessageRecipient(); $recipient->toAddress = $notification->owner->primaryEmail->emailAddress; $recipient->toName = strval($notification->owner); $recipient->type = EmailMessageRecipient::TYPE_TO; $recipient->personsOrAccounts->add($notification->owner); $emailMessage->recipients->add($recipient); $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME); $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT); if (!$emailMessage->save()) { throw new FailedToSaveModelException(); } try { Yii::app()->emailHelper->sendImmediately($emailMessage); } catch (CException $e) { //Not sure what to do yet when catching an exception here. Currently ignoring gracefully. } } }
/** * Process and create email message. Used for testing outbound setting, and outbound job * @param array $from * @param string $toAddress * @return \EmailMessage */ public static function processAndCreateTestEmailMessage(array $from, $toAddress) { assert('is_string($from["name"])'); assert('is_string($from["address"])'); $emailMessage = new EmailMessage(); $emailMessage->owner = Yii::app()->user->userModel; $emailMessage->subject = Zurmo::t('EmailMessagesModule', 'A test email from Zurmo', LabelUtil::getTranslationParamsForAllModules()); $emailContent = new EmailMessageContent(); $userProfileUrl = Yii::app()->createAbsoluteUrl('users/default/details', array('id' => Yii::app()->user->userModel->id)); $textEmailContent = Zurmo::t('EmailMessagesModule', 'A test text message from Zurmo.', LabelUtil::getTranslationParamsForAllModules()) . PHP_EOL; $textEmailContent .= Zurmo::t('EmailMessagesModule', 'Sent from {username}: {usernameLink}.', array('{username}' => Yii::app()->user->userModel->username, '{usernameLink}' => $userProfileUrl)) . PHP_EOL; $emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate($textEmailContent); $htmlEmailContent = ZurmoHtml::tag('p', array(), Zurmo::t('EmailMessagesModule', 'A test text message from Zurmo.', LabelUtil::getTranslationParamsForAllModules())); $htmlEmailContent .= ZurmoHtml::tag('p', array(), Zurmo::t('EmailMessagesModule', 'Sent from {usernameLink}.', array('{usernameLink}' => ZurmoHtml::link(Yii::app()->user->userModel->username, $userProfileUrl)))); $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate($htmlEmailContent, Yii::app()->user->userModel, true); $emailMessage->content = $emailContent; $sender = new EmailMessageSender(); $sender->fromAddress = $from['address']; $sender->fromName = $from['name']; $emailMessage->sender = $sender; $recipient = new EmailMessageRecipient(); $recipient->toAddress = $toAddress; $recipient->toName = 'Test Recipient'; $recipient->type = EmailMessageRecipient::TYPE_TO; $emailMessage->recipients->add($recipient); $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME); $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT); return $emailMessage; }
/** * @param Mission $mission * @return EmailMessageContent */ public static function getEmailContent(Mission $mission) { $emailContent = new EmailMessageContent(); $url = CommentsUtil::getUrlToEmail($mission); $textContent = Zurmo::t('MissionsModule', "Hello, {lineBreak}There is a new mission. " . "Be the first one to start it and get this great reward: {reward}." . "{lineBreak}{lineBreak} {url}", array('{lineBreak}' => "\n", '{reward}' => $mission->reward, '{url}' => ZurmoHtml::link($url, $url))); $emailContent->textContent = $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationTextTemplate($textContent); $htmlContent = Zurmo::t('MissionsModule', "Hello, {lineBreak}There is a new {url}. " . "Be the first one to start it and get this great reward: {reward}.", array('{lineBreak}' => "<br/>", '{strongStartTag}' => '<strong>', '{strongEndTag}' => '</strong>', '{reward}' => $mission->reward, '{url}' => ZurmoHtml::link($mission->getModelLabelByTypeAndLanguage('SingularLowerCase'), $url))); $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate($htmlContent); return $emailContent; }