/**
  * Testing that each model type can render properly and does not throw an exception
  */
 public function testRenderSummaryContentWithEmailMessage()
 {
     $super = User::getByUsername('super');
     $billy = User::getByUsername('billy');
     $this->assertEquals(0, count(EmailMessage::getAll()));
     $emailMessage = new EmailMessage();
     $emailMessage->owner = BaseJobControlUserConfigUtil::getUserToRunAs();
     $emailMessage->subject = 'My First Email';
     //Set sender, and recipient, and content
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = 'My First Message';
     $emailContent->htmlContent = 'Some fake HTML content';
     $emailMessage->content = $emailContent;
     //Sending from the system, does not have a 'person'.
     $sender = new EmailMessageSender();
     $sender->fromAddress = '*****@*****.**';
     $sender->fromName = 'Zurmo System';
     $sender->personOrAccount = $super;
     $emailMessage->sender = $sender;
     //Recipient is billy.
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Billy James';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $recipient->personOrAccount = $billy;
     $emailMessage->recipients->add($recipient);
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'HomeModule');
     $content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER, 'HomeModule');
     $content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'UserModule');
     $content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER, 'UserModule');
 }
 /**
  * A notification email is different than a regular outbound email because it is owned by a super user
  * that is different than the user logged in.  So the sender does not have a 'person'
  */
 public function testCreateEmailMessageThatIsANotification()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $billy = User::getByUsername('billy');
     $this->assertEquals(0, count(EmailMessage::getAll()));
     $emailMessage = new EmailMessage();
     $emailMessage->owner = BaseJobControlUserConfigUtil::getUserToRunAs();
     $emailMessage->subject = 'My First Email';
     //Set sender, and recipient, and content
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = 'My First Message';
     $emailContent->htmlContent = 'Some fake HTML content';
     $emailMessage->content = $emailContent;
     //Sending from the system, does not have a 'person'.
     $sender = new EmailMessageSender();
     $sender->fromAddress = '*****@*****.**';
     $sender->fromName = 'Zurmo System';
     $emailMessage->sender = $sender;
     //Recipient is billy.
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Billy James';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $recipient->personOrAccount = $billy;
     $emailMessage->recipients->add($recipient);
     //At this point the message is in no folder
     $this->assertTrue($emailMessage->folder->id < 0);
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
     //Save, at this point the email should be in the draft folder
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $this->assertTrue($emailMessage->folder->id > 0);
     $this->assertEquals(0, count(EmailMessageSendError::getAll()));
     $emailMessageSendError = new EmailMessageSendError();
     $data = array();
     $data['message'] = 'error message';
     $emailMessageSendError->serializedData = serialize($data);
     $emailMessage->folder = EmailFolder::getByBoxAndType($emailMessage->folder->emailBox, EmailFolder::TYPE_OUTBOX_ERROR);
     $emailMessage->error = $emailMessageSendError;
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $this->assertEquals(1, count(EmailMessageSendError::getAll()));
     //Now swap the error with a new one
     $emailMessageId = $emailMessage->id;
     $emailMessage->forget();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $emailMessageSendError = new EmailMessageSendError();
     $data = array();
     $data['message'] = 'error message 2';
     $emailMessageSendError->serializedData = serialize($data);
     $emailMessage->error = $emailMessageSendError;
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $this->assertEquals(1, count(EmailMessageSendError::getAll()));
 }
 /**
  * A notification email is different than a regular outbound email because it is owned by a super user
  * that is different than the user logged in.  So the sender does not have a 'person'
  */
 public function testCreateEmailMessageThatIsANotification()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $billy = User::getByUsername('billy');
     $this->assertEquals(0, count(EmailMessage::getAll()));
     $emailMessage = new EmailMessage();
     $emailMessage->owner = BaseJobControlUserConfigUtil::getUserToRunAs();
     $emailMessage->subject = 'My First Email';
     //Attempt to save without setting required information
     $saved = $emailMessage->save();
     $this->assertFalse($saved);
     $compareData = array('folder' => array('name' => array('Name cannot be blank.'), 'emailBox' => array('name' => array('Name cannot be blank.'))), 'sender' => array('fromAddress' => array('From Address cannot be blank.')));
     $this->assertEquals($compareData, $emailMessage->getErrors());
     //Set sender, and recipient, and content
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = 'My First Message';
     $emailContent->htmlContent = 'Some fake HTML content';
     $emailMessage->content = $emailContent;
     //Sending from the system, does not have a 'person'.
     $sender = new EmailMessageSender();
     $sender->fromAddress = '*****@*****.**';
     $sender->fromName = 'Zurmo System';
     $emailMessage->sender = $sender;
     //Recipient is billy.
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Billy James';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $recipient->personOrAccount = $billy;
     $emailMessage->recipients->add($recipient);
     //At this point the message is in no folder
     $this->assertTrue($emailMessage->folder->id < 0);
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
     //Save, at this point the email should be in the draft folder
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $this->assertTrue($emailMessage->folder->id > 0);
     //At this point the message should be in the draft folder by default.
     $this->assertEquals(EmailFolder::getDefaultDraftName(), $emailMessage->folder->name);
     $this->assertEquals(EmailFolder::TYPE_DRAFT, $emailMessage->folder->type);
 }
 /**
  * @see BaseJob::run()
  */
 public function run()
 {
     try {
         $originalUser = Yii::app()->user->userModel;
         Yii::app()->user->userModel = BaseJobControlUserConfigUtil::getUserToRunAs();
         foreach (WorkflowMessageInQueue::getModelsToProcess(self::$pageSize) as $workflowMessageInQueue) {
             try {
                 $model = $this->resolveModel($workflowMessageInQueue);
                 $this->resolveSavedWorkflowIsValid($workflowMessageInQueue);
                 $this->processWorkflowMessageInQueue($workflowMessageInQueue, $model);
             } catch (NotFoundException $e) {
             }
             $workflowMessageInQueue->delete();
         }
         Yii::app()->user->userModel = $originalUser;
         return true;
     } catch (MissingASuperAdministratorException $e) {
         //skip running workflow, since no super administrators are available.
         $this->errorMessage = Zurmo::t('WorkflowsModule', 'Could not process since no super administrators were found');
         return false;
     }
 }
 /**
  * Send system email message
  * @param string $subject
  * @param array $recipients
  * @param string $textContent
  * @param string $htmlContent
  * @throws NotSupportedException
  */
 public static function sendSystemEmail($subject, $recipients, $textContent = '', $htmlContent = '')
 {
     $emailMessage = new EmailMessage();
     $emailMessage->owner = BaseJobControlUserConfigUtil::getUserToRunAs();
     $emailMessage->subject = $subject;
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = $textContent;
     $emailContent->htmlContent = $htmlContent;
     $emailMessage->content = $emailContent;
     $sender = new EmailMessageSender();
     $sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser(Yii::app()->user->userModel);
     $sender->fromName = strval(Yii::app()->user->userModel);
     $sender->personOrAccount = Yii::app()->user->userModel;
     $emailMessage->sender = $sender;
     foreach ($recipients as $recipientEmail) {
         $recipient = new EmailMessageRecipient();
         $recipient->toAddress = $recipientEmail;
         $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) {
         throw new NotSupportedException();
     }
     Yii::app()->emailHelper->sendImmediately($emailMessage);
     $saved = $emailMessage->save();
     if (!$saved) {
         throw new NotSupportedException();
     }
     if (!$emailMessage->hasSendError()) {
         return true;
     } else {
         return false;
     }
 }
 /**
  *
  * (non-PHPdoc)
  * @see BaseJob::run()
  */
 public function run()
 {
     $messageContent = null;
     $userToSendMessagesFrom = BaseJobControlUserConfigUtil::getUserToRunAs();
     $emailMessage = new EmailMessage();
     $emailMessage->owner = Yii::app()->user->userModel;
     $emailMessage->subject = Zurmo::t('EmailMessagesModule', 'A test email from Zurmo');
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = Zurmo::t('EmailMessagesModule', 'A test text message from Zurmo.');
     $emailContent->htmlContent = Zurmo::t('EmailMessagesModule', 'A test text message from Zurmo.');
     $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 = Yii::app()->emailHelper->defaultTestToAddress;
     $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) {
         throw new NotSupportedException();
     }
     Yii::app()->emailHelper->sendImmediately($emailMessage);
     if (!$emailMessage->hasSendError()) {
         $messageContent .= Zurmo::t('EmailMessagesModule', 'Message successfully sent') . "\n";
         return true;
     } else {
         $messageContent .= Zurmo::t('EmailMessagesModule', 'Message failed to send') . "\n";
         $messageContent .= $emailMessage->error . "\n";
         $this->errorMessage = $messageContent;
         return false;
     }
 }
Exemple #7
0
 /**
  * Execute the action.
  * @param array command line parameters specific for this command
  */
 public function actionSend($username, $toAddress, $subject = 'A test email from Zurmo', $textContent = 'A test text message from Zurmo.', $htmlContent = 'A test html message from Zurmo.', $host = null, $port = null, $outboundUsername = null, $outboundPassword = null, $outboundSecurity = null)
 {
     if (!isset($username)) {
         $this->usageError('A username must be specified.');
     }
     if (!isset($toAddress)) {
         $this->usageError('You must specify a to address.');
     }
     try {
         Yii::app()->user->userModel = User::getByUsername($username);
     } catch (NotFoundException $e) {
         $this->usageError('The specified username does not exist.');
     }
     if ($host != null) {
         Yii::app()->emailHelper->outboundHost = $host;
     }
     if ($port != null) {
         Yii::app()->emailHelper->outboundPort = $port;
     }
     if ($outboundUsername != null) {
         Yii::app()->emailHelper->outboundUsername = $outboundUsername;
     }
     if ($outboundUsername != null) {
         Yii::app()->emailHelper->outboundPassword = $outboundPassword;
     }
     if ($outboundSecurity != null && $outboundSecurity != '' && $outboundSecurity != 'false') {
         Yii::app()->emailHelper->outboundSecurity = $outboundSecurity;
     } else {
         Yii::app()->emailHelper->outboundSecurity = null;
     }
     echo "\n";
     echo 'Using type:' . Yii::app()->emailHelper->outboundType . "\n";
     echo 'Using host:' . Yii::app()->emailHelper->outboundHost . "\n";
     echo 'Using port:' . Yii::app()->emailHelper->outboundPort . "\n";
     echo 'Using username:'******'Using password:'******'Using outbound security:' . Yii::app()->emailHelper->outboundSecurity . "\n\n";
     } else {
         echo 'Using outbound security: none' . "\n\n";
     }
     echo 'Sending Email Message' . "\n";
     $emailMessage = new EmailMessage();
     $emailMessage->owner = BaseJobControlUserConfigUtil::getUserToRunAs();
     $emailMessage->subject = $subject;
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = $textContent;
     $emailContent->htmlContent = $htmlContent;
     $emailMessage->content = $emailContent;
     $sender = new EmailMessageSender();
     $sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser(Yii::app()->user->userModel);
     $sender->fromName = strval(Yii::app()->user->userModel);
     $sender->personOrAccount = Yii::app()->user->userModel;
     $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) {
         $this->addErrorsAsUsageErrors($emailMessage->getErrors());
     }
     Yii::app()->emailHelper->sendImmediately($emailMessage);
     if (!$emailMessage->hasSendError()) {
         echo Zurmo::t('Commands', 'Message successfully sent') . "\n";
     } else {
         echo Zurmo::t('Commands', 'Message failed to send') . "\n";
         echo $emailMessage->error . "\n";
     }
     $saved = $emailMessage->save();
     if (!$saved) {
         throw new NotSupportedException();
     }
 }
 protected static function sendEmail(Notification $notification)
 {
     if ($notification->owner->primaryEmail->emailAddress !== null && !UserConfigurationFormAdapter::resolveAndGetValue($notification->owner, 'turnOffEmailNotifications')) {
         $userToSendMessagesFrom = BaseJobControlUserConfigUtil::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->personOrAccount = $notification->owner;
         $emailMessage->recipients->add($recipient);
         $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
         $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
         try {
             Yii::app()->emailHelper->sendImmediately($emailMessage);
         } catch (CException $e) {
             //Not sure what to do yet when catching an exception here. Currently ignoring gracefully.
         }
     }
 }
 protected static function resolveSender(MarketingList $marketingList, $itemOwnerModel)
 {
     $sender = new EmailMessageSender();
     if (get_class($itemOwnerModel) == 'Campaign') {
         $sender->fromAddress = $itemOwnerModel->fromAddress;
         $sender->fromName = $itemOwnerModel->fromName;
         return $sender;
     }
     if (!empty($marketingList->fromName) && !empty($marketingList->fromAddress)) {
         $sender->fromAddress = $marketingList->fromAddress;
         $sender->fromName = $marketingList->fromName;
     } else {
         $userToSendMessagesFrom = BaseJobControlUserConfigUtil::getUserToRunAs();
         $sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom);
         $sender->fromName = strval($userToSendMessagesFrom);
     }
     return $sender;
 }
 /**
  * @return EmailMessageSender
  * @throws NotSupportedException
  */
 protected function resolveSender()
 {
     $sender = new EmailMessageSender();
     if ($this->emailMessageForm->sendFromType == EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT) {
         $userToSendMessagesFrom = BaseJobControlUserConfigUtil::getUserToRunAs();
         $sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom);
         $sender->fromName = strval($userToSendMessagesFrom);
     } elseif ($this->emailMessageForm->sendFromType == EmailMessageForWorkflowForm::SEND_FROM_TYPE_CUSTOM) {
         $sender->fromAddress = $this->emailMessageForm->sendFromAddress;
         $sender->fromName = $this->emailMessageForm->sendFromName;
     } else {
         throw new NotSupportedException();
     }
     return $sender;
 }
 /**
  * @depends testProcessDueAutoresponderItemDoesNotThrowExceptionWhenContactHasNoPrimaryEmail
  */
 public function testProcessDueAutoresponderItemDoesNotThrowExceptionWhenContactHasPrimaryEmail()
 {
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     $contact = ContactTestHelper::createContactByNameForOwner('contact 03', $this->user);
     $contact->primaryEmail = $email;
     $this->assertTrue($contact->save());
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 03');
     $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 03', 'text content', 'html content', 1, Autoresponder::OPERATION_SUBSCRIBE, true, $marketingList);
     $processed = 0;
     $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $autoresponderItem = AutoresponderItemTestHelper::createAutoresponderItem($processed, $processDateTime, $autoresponder, $contact);
     AutoresponderItemsUtil::processDueItem($autoresponderItem);
     $this->assertEquals(1, $autoresponderItem->processed);
     $emailMessage = $autoresponderItem->emailMessage;
     $this->assertEquals($marketingList->owner, $emailMessage->owner);
     $marketingListPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($marketingList);
     $emailMessagePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($emailMessage);
     $this->assertEquals($marketingListPermissions, $emailMessagePermissions);
     $this->assertEquals($autoresponder->subject, $emailMessage->subject);
     $this->assertTrue(strpos($emailMessage->content->textContent, $autoresponder->textContent) !== false);
     $this->assertTrue(strpos($emailMessage->content->textContent, '/marketingLists/external/') !== false);
     $this->assertEquals(2, substr_count($emailMessage->content->textContent, '/marketingLists/external/'));
     $this->assertTrue(strpos($emailMessage->content->htmlContent, $autoresponder->htmlContent) !== false);
     $this->assertTrue(strpos($emailMessage->content->htmlContent, '/marketingLists/external/') !== false);
     $this->assertEquals(2, substr_count($emailMessage->content->htmlContent, '/marketingLists/external/'));
     $userToSendMessagesFrom = BaseJobControlUserConfigUtil::getUserToRunAs();
     $defaultFromAddress = Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom);
     $defaultFromName = strval($userToSendMessagesFrom);
     $this->assertEquals($defaultFromAddress, $emailMessage->sender->fromAddress);
     $this->assertEquals($defaultFromName, $emailMessage->sender->fromName);
     $this->assertEquals(1, $emailMessage->recipients->count());
     $recipients = $emailMessage->recipients;
     $this->assertEquals(strval($contact), $recipients[0]->toName);
     $this->assertEquals($email->emailAddress, $recipients[0]->toAddress);
     $this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipients[0]->type);
     $this->assertEquals($contact, $recipients[0]->personOrAccount);
     $headersArray = array('zurmoItemId' => $autoresponderItem->id, 'zurmoItemClass' => get_class($autoresponderItem), 'zurmoPersonId' => $contact->getClassId('Person'));
     $expectedHeaders = serialize($headersArray);
     $this->assertEquals($expectedHeaders, $emailMessage->headers);
 }
 /**
  * Assumes before calling this, the outbound settings have been validated in the form.
  * Todo: When new user interface is complete, this will be re-worked to be on page instead of modal.
  */
 public function actionSendTestMessage()
 {
     $configurationForm = EmailSmtpConfigurationFormAdapter::makeFormFromGlobalConfiguration();
     $postVariableName = get_class($configurationForm);
     if (isset($_POST[$postVariableName]) || isset($_POST['UserEmailConfigurationForm'])) {
         if (isset($_POST[$postVariableName])) {
             $configurationForm->setAttributes($_POST[$postVariableName]);
         } else {
             $configurationForm->host = $_POST['UserEmailConfigurationForm']['outboundHost'];
             $configurationForm->port = $_POST['UserEmailConfigurationForm']['outboundPort'];
             $configurationForm->username = $_POST['UserEmailConfigurationForm']['outboundUsername'];
             $configurationForm->password = $_POST['UserEmailConfigurationForm']['outboundPassword'];
             $configurationForm->security = $_POST['UserEmailConfigurationForm']['outboundSecurity'];
             $configurationForm->aTestToAddress = $_POST['UserEmailConfigurationForm']['aTestToAddress'];
             $fromNameToSendMessagesFrom = $_POST['UserEmailConfigurationForm']['fromName'];
             $fromAddressToSendMessagesFrom = $_POST['UserEmailConfigurationForm']['fromAddress'];
         }
         if ($configurationForm->aTestToAddress != null) {
             $emailHelper = new EmailHelper();
             $emailHelper->loadDefaultFromAndToAddresses();
             $emailHelper->outboundHost = $configurationForm->host;
             $emailHelper->outboundPort = $configurationForm->port;
             $emailHelper->outboundUsername = $configurationForm->username;
             $emailHelper->outboundPassword = $configurationForm->password;
             $emailHelper->outboundSecurity = $configurationForm->security;
             if (isset($fromNameToSendMessagesFrom) && isset($fromAddressToSendMessagesFrom)) {
                 $from = array('name' => $fromNameToSendMessagesFrom, 'address' => $fromAddressToSendMessagesFrom);
                 $emailMessage = EmailMessageHelper::sendTestEmail($emailHelper, $from, $configurationForm->aTestToAddress);
             } else {
                 $user = BaseJobControlUserConfigUtil::getUserToRunAs();
                 $userToSendMessagesFrom = User::getById((int) $user->id);
                 $emailMessage = EmailMessageHelper::sendTestEmailFromUser($emailHelper, $userToSendMessagesFrom, $configurationForm->aTestToAddress);
             }
             $messageContent = null;
             if (!($emailMessage->hasErrors() || $emailMessage->hasSendError())) {
                 $messageContent .= Zurmo::t('EmailMessagesModule', 'Message successfully sent') . "\n";
             } else {
                 $messageContent .= Zurmo::t('EmailMessagesModule', 'Message failed to send') . "\n";
                 if ($emailMessage->hasSendError()) {
                     $messageContent .= $emailMessage->error . "\n";
                 } else {
                     $errors = $emailMessage->getErrors();
                     $data = array();
                     foreach ($errors as $attributeNameWithErrors) {
                         foreach ($attributeNameWithErrors as $attributeError) {
                             $messageContent .= reset($attributeError) . "\n";
                         }
                     }
                 }
             }
         } else {
             $messageContent = Zurmo::t('EmailMessagesModule', 'A test email address must be entered before you can send a test email.') . "\n";
         }
         Yii::app()->getClientScript()->setToAjaxMode();
         $messageView = new TestEmailMessageView($messageContent);
         $view = new ModalView($this, $messageView);
         echo $view->render();
     } else {
         throw new NotSupportedException();
     }
 }