コード例 #1
0
 /**
  * Override to avoid actually sending emails out through transport.
  * (non-PHPdoc)
  * @see ZurmoSwiftMailer::sendEmail()
  */
 public function sendEmail()
 {
     $emailMessage = $this->emailMessage;
     $sendEmailThroughTransport = Yii::app()->emailHelper->sendEmailThroughTransport;
     if (!$sendEmailThroughTransport) {
         $emailMessage->error = null;
         $emailMessage->folder = EmailFolder::getByBoxAndType($emailMessage->folder->emailBox, EmailFolder::TYPE_SENT);
         $emailMessage->sendAttempts = $emailMessage->sendAttempts + 1;
         $emailMessage->save();
     } else {
         parent::sendEmail();
     }
 }
コード例 #2
0
ファイル: EmailHelper.php プロジェクト: sandeep1027/zurmo_
 protected function getOutboundMailer()
 {
     $mailer = new ZurmoSwiftMailer();
     $mailer->init();
     return $mailer;
 }
コード例 #3
0
 /**
  * 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 {
             //Check for sendgrid
             if ($_POST['UserEmailConfigurationForm']['useCustomOutboundSettings'] == EmailMessageUtil::OUTBOUND_PERSONAL_SENDGRID_SETTINGS) {
                 $this->processSendTestMessageForSendGrid();
             } 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) {
             $emailAccount = new EmailAccount();
             $emailAccount->outboundHost = $configurationForm->host;
             $emailAccount->outboundPort = $configurationForm->port;
             $emailAccount->outboundUsername = $configurationForm->username;
             $emailAccount->outboundPassword = ZurmoPasswordSecurityUtil::encrypt($configurationForm->password);
             $emailAccount->outboundSecurity = $configurationForm->security;
             $isUser = false;
             if (isset($fromNameToSendMessagesFrom) && isset($fromAddressToSendMessagesFrom)) {
                 $isUser = true;
                 $from = array('name' => $fromNameToSendMessagesFrom, 'address' => $fromAddressToSendMessagesFrom);
             } else {
                 $user = BaseControlUserConfigUtil::getUserToRunAs();
                 $userToSendMessagesFrom = User::getById((int) $user->id);
                 $from = array('name' => Yii::app()->emailHelper->resolveFromNameForSystemUser($userToSendMessagesFrom), 'address' => Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom));
             }
             $emailMessage = EmailMessageHelper::processAndCreateEmailMessage($from, $configurationForm->aTestToAddress);
             $mailer = new ZurmoSwiftMailer($emailMessage, $emailAccount);
             $emailMessage = $mailer->sendTestEmail($isUser);
             $messageContent = EmailHelper::prepareMessageContent($emailMessage);
         } 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 TestConnectionView($messageContent);
         $view = new ModalView($this, $messageView);
         echo $view->render();
     } else {
         throw new NotSupportedException();
     }
 }
コード例 #4
0
 /**
  * For testing only
  * @param string $subject
  * @param string $from
  * @param mixed(string || array) $to
  * @param string $textContent
  * @param string $htmlContent
  * @param mixed(string || array) $cc
  * @param mixed(string || array) $bcc
  * @param array $attachments
  * @param array $settings
  * @param array $headers
  * @param array $parts
  */
 public function sendRawEmail($subject, $from, $to, $textContent = '', $htmlContent = '', $cc = null, $bcc = null, $attachments = null, $settings = null, $headers = array(), $parts = array())
 {
     assert('is_string($subject) && $subject != ""');
     assert('is_string($from)    && $from != ""');
     assert('(is_array($to) && !empty($to)) || is_string($to) || !isset($to)');
     assert('is_string($textContent) || $textContent == null');
     assert('is_string($htmlContent) || $htmlContent == null');
     assert('(is_array($cc) && !empty($cc)) || is_string($cc) || !isset($cc)');
     assert('(is_array($bcc) && !empty($bcc)) || is_string($bcc) || !isset($bcc)');
     assert('isset($to) || isset($cc) || isset($bcc)');
     assert('is_array($attachments) || !isset($attachments)');
     assert('is_array($parts) || !isset($parts)');
     $toName = null;
     $toAddress = null;
     if (is_string($to)) {
         $toAddress = $to;
     } elseif (is_array($to)) {
         foreach ($to as $key => $value) {
             $toName = $key;
             $toAddress = $value;
         }
     }
     $emailMessage = EmailMessageTestHelper::createOutboxEmail(Yii::app()->user->userModel, $subject, $htmlContent, $textContent, null, $from, $toName, $toAddress, $cc, $bcc);
     $mailer = new ZurmoSwiftMailer($emailMessage, null);
     if (!empty($parts)) {
         $mailer->parts = $parts;
     }
     $mailer->From = $from;
     if (is_array($to) && !empty($to)) {
         foreach ($to as $recipientEmail) {
             $mailer->addAddressByType($recipientEmail, '', EmailMessageRecipient::TYPE_TO);
         }
     } elseif (is_string($to)) {
         $mailer->addAddressByType($to, '', EmailMessageRecipient::TYPE_TO);
     }
     if (is_array($cc) && !empty($cc)) {
         foreach ($cc as $recipientEmail) {
             $mailer->addAddressByType($recipientEmail, '', EmailMessageRecipient::TYPE_CC);
         }
     } elseif (is_string($cc)) {
         $mailer->addAddressByType($cc, '', EmailMessageRecipient::TYPE_CC);
     }
     if (is_array($bcc) && !empty($bcc)) {
         foreach ($bcc as $recipientEmail) {
             $mailer->addAddressByType($recipientEmail, '', EmailMessageRecipient::TYPE_BCC);
         }
     } elseif (is_string($bcc)) {
         $mailer->addAddressByType($bcc, '', EmailMessageRecipient::TYPE_BCC);
     }
     if (isset($attachments) && !empty($attachments)) {
         foreach ($attachments as $file) {
             $mailer->attachFromPath($file);
         }
     }
     $mailer->headers = $headers;
     $acceptedRecipients = $mailer->send();
     if ($acceptedRecipients > 0) {
         // Do nothing
     } else {
         // To-Do: make exception or something else
         echo "There was error while sending email";
     }
 }