예제 #1
0
 /**
  * Bounce message to sender.
  *
  * @param   object  $message parsed message structure.
  * @param   array   array(ERROR_CODE, ERROR_STRING) of error to bounce
  * @return  void
  */
 public function bounceMessage($message, $error)
 {
     // open text template
     $tpl = new Template_Helper();
     $tpl->setTemplate('notifications/bounced_email.tpl.text');
     $tpl->assign(array('error_code' => $error[0], 'error_message' => $error[1], 'date' => $message->date, 'subject' => Mime_Helper::fixEncoding($message->subject), 'from' => Mime_Helper::fixEncoding($message->fromaddress), 'to' => Mime_Helper::fixEncoding($message->toaddress), 'cc' => Mime_Helper::fixEncoding(@$message->ccaddress)));
     $sender_email = Mail_Helper::getEmailAddress($message->fromaddress);
     $usr_id = User::getUserIDByEmail($sender_email);
     // change the current locale
     if ($usr_id) {
         Language::set(User::getLang($usr_id));
     }
     $text_message = $tpl->getTemplateContents();
     // send email (use PEAR's classes)
     $mail = new Mail_Helper();
     $mail->setTextBody($text_message);
     $setup = $mail->getSMTPSettings();
     $mail->send($setup['from'], $sender_email, APP_SHORT_NAME . ': ' . ev_gettext('Postmaster notify: see transcript for details'));
     if ($usr_id) {
         Language::restore();
     }
 }
예제 #2
0
 /**
  * Connects to the SMTP server and sends the queued message.
  *
  * @param   string $recipient The recipient of this message
  * @param   string $text_headers The full headers of this message
  * @param   string $body The full body of this message
  * @param   string $status The status of this message
  * @return  true, or a PEAR_Error object
  */
 private function _sendEmail($recipient, $text_headers, &$body, $status)
 {
     $header_names = Mime_Helper::getHeaderNames($text_headers);
     $_headers = self::_getHeaders($text_headers, $body);
     $headers = array();
     foreach ($_headers as $lowercase_name => $value) {
         // need to remove the quotes to avoid a parsing problem
         // on senders that have extended characters in the first
         // or last words in their sender name
         if ($lowercase_name == 'from') {
             $value = Mime_Helper::removeQuotes($value);
         }
         $value = Mime_Helper::encode($value);
         // add the quotes back
         if ($lowercase_name == 'from') {
             $value = Mime_Helper::quoteSender($value);
         }
         $headers[$header_names[$lowercase_name]] = $value;
     }
     // remove any Reply-To:/Return-Path: values from outgoing messages
     unset($headers['Reply-To']);
     unset($headers['Return-Path']);
     // mutt sucks, so let's remove the broken Mime-Version header and add the proper one
     if (in_array('Mime-Version', array_keys($headers))) {
         unset($headers['Mime-Version']);
         $headers['MIME-Version'] = '1.0';
     }
     $mail = Mail::factory('smtp', Mail_Helper::getSMTPSettings());
     $res = $mail->send($recipient, $headers, $body);
     if (Misc::isError($res)) {
         // special handling of errors when the mail server is down
         $msg = $res->getMessage();
         $cant_notify = $status == 'error' || strstr($msg, 'unable to connect to smtp server') || stristr($msg, 'Failed to connect to') !== false;
         Error_Handler::logError(array($msg, $res->getDebugInfo()), __FILE__, __LINE__, !$cant_notify);
         return $res;
     }
     return true;
 }
 /**
  * Method used to send an alert to a set of email addresses when
  * a reminder action was triggered, but no action was really
  * taken because no recipients could be found.
  *
  * @param   integer $issue_id The issue ID
  * @param   string $type Which reminder are we trying to send, email or sms
  * @param   array $reminder The reminder details
  * @param   array $action The action details
  * @return  void
  */
 private function _recordNoRecipientError($issue_id, $type, $reminder, $action, $data, $conditions)
 {
     $to = Reminder::_getReminderAlertAddresses();
     if (count($to) > 0) {
         $tpl = new Template_Helper();
         $tpl->setTemplate('reminders/alert_no_recipients.tpl.text');
         $tpl->assign(array('type' => $type, 'data' => $data, 'reminder' => $reminder, 'action' => $action, 'conditions' => $conditions, 'has_customer_integration' => CRM::hasCustomerIntegration(Issue::getProjectID($issue_id))));
         $text_message = $tpl->getTemplateContents();
         foreach ($to as $address) {
             // send email (use PEAR's classes)
             $mail = new Mail_Helper();
             $mail->setTextBody($text_message);
             $setup = $mail->getSMTPSettings();
             // TRANSLATORS: %1 = issue_id, %2 - rma_title
             $subject = ev_gettext('[#%1$s] Reminder Not Triggered: [#%2$s]', $issue_id, $action['rma_title']);
             $mail->send($setup['from'], $address, $subject, 0, $issue_id);
         }
     }
 }
예제 #4
0
 /**
  * Connects to the SMTP server and sends the queued message.
  *
  * @param   string $recipient The recipient of this message
  * @param   string $text_headers The full headers of this message
  * @param   string $body The full body of this message
  * @param   string $status The status of this message
  * @return  true, or a PEAR_Error object
  */
 private function _sendEmail($recipient, $text_headers, &$body, $status)
 {
     $header_names = Mime_Helper::getHeaderNames($text_headers);
     $_headers = self::_getHeaders($text_headers, $body);
     $headers = array();
     foreach ($_headers as $lowercase_name => $value) {
         // need to remove the quotes to avoid a parsing problem
         // on senders that have extended characters in the first
         // or last words in their sender name
         if ($lowercase_name == 'from') {
             $value = Mime_Helper::removeQuotes($value);
         }
         $value = Mime_Helper::encode($value);
         // add the quotes back
         if ($lowercase_name == 'from') {
             $value = Mime_Helper::quoteSender($value);
         }
         $headers[$header_names[$lowercase_name]] = $value;
     }
     // remove any Reply-To:/Return-Path: values from outgoing messages
     unset($headers['Reply-To']);
     unset($headers['Return-Path']);
     // mutt sucks, so let's remove the broken Mime-Version header and add the proper one
     if (in_array('Mime-Version', array_keys($headers))) {
         unset($headers['Mime-Version']);
         $headers['MIME-Version'] = '1.0';
     }
     $mail = Mail::factory('smtp', Mail_Helper::getSMTPSettings());
     $res = $mail->send($recipient, $headers, $body);
     if (Misc::isError($res)) {
         Logger::app()->error($res->getMessage(), array('debug' => $res->getDebugInfo()));
         return $res;
     }
     return true;
 }
예제 #5
0
 /**
  * Method used to send the account details of an user.
  *
  * @param   integer $usr_id The user ID
  * @return  void
  */
 public function notifyAccountDetails($usr_id)
 {
     $info = User::getDetails($usr_id);
     $info['projects'] = Project::getAssocList($usr_id, true, true);
     // open text template
     $tpl = new Template_Helper();
     $tpl->setTemplate('notifications/account_details.tpl.text');
     $tpl->assign(array('app_title' => Misc::getToolCaption(), 'user' => $info));
     Language::set(User::getLang($usr_id));
     $text_message = $tpl->getTemplateContents();
     // send email (use PEAR's classes)
     $mail = new Mail_Helper();
     $mail->setTextBody($text_message);
     $setup = $mail->getSMTPSettings();
     $to = $mail->getFormattedName($info['usr_full_name'], $info['usr_email']);
     // TRANSLATORS: %s = APP_SHORT_NAME
     $subject = ev_gettext('%s: Your User Account Details', APP_SHORT_NAME);
     $mail->send($setup['from'], $to, $subject);
     Language::restore();
 }