/** * send a notification as email * * @param Tinebase_Model_FullUser $_updater * @param Addressbook_Model_Contact $_recipient * @param string $_subject the subject * @param string $_messagePlain the message as plain text * @param string $_messageHtml the message as html * @param string|array $_attachments */ public function send($_updater, Addressbook_Model_Contact $_recipient, $_subject, $_messagePlain, $_messageHtml = NULL, $_attachments = NULL) { // create mail object $mail = new Tinebase_Mail('UTF-8'); // this seems to break some subjects, removing it for the moment // -> see 0004070: sometimes we can't decode message subjects (calendar notifications?) //$mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64); $mail->setSubject($_subject); $mail->setBodyText($_messagePlain); if ($_messageHtml !== NULL) { $mail->setBodyHtml($_messageHtml); } // add header to identify mails sent by notification service / don't reply to this mail, dear autoresponder ... :) $mail->addHeader('X-Tine20-Type', 'Notification'); $mail->addHeader('Precedence', 'bulk'); $mail->addHeader('User-Agent', Tinebase_Core::getTineUserAgent('Notification Service')); if (empty($this->_fromAddress)) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' No notification service address set. Could not send notification.'); return; } if ($_updater !== NULL && !empty($_updater->accountEmailAddress)) { $mail->setFrom($_updater->accountEmailAddress, $_updater->accountFullName); $mail->setSender($this->_fromAddress, $this->_fromName); } else { $mail->setFrom($this->_fromAddress, $this->_fromName); } // attachments if (is_array($_attachments)) { $attachments =& $_attachments; } elseif (is_string($_attachments)) { $attachments = array(&$_attachments); } else { $attachments = array(); } foreach ($attachments as $attachment) { if ($attachment instanceof Zend_Mime_Part) { $mail->addAttachment($attachment); } else { if (isset($attachment['filename'])) { $mail->createAttachment($attachment['rawdata'], Zend_Mime::TYPE_OCTETSTREAM, Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $attachment['filename']); } else { $mail->createAttachment($attachment); } } } // send if (!empty($_recipient->email)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Send notification email to ' . $_recipient->email); } $mail->addTo($_recipient->email, $_recipient->n_fn); Tinebase_Smtp::getInstance()->sendMessage($mail); } else { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Not sending notification email to ' . $_recipient->n_fn . '. No email address available.'); } }
/** * testResourceNotification * * checks if notification mail is sent to configured mail address of a resource * * @see 0009954: resource manager and email handling * * @param boolean $suppress_notification */ public function testResourceNotification($suppress_notification = false) { // create resource with email address of unittest user $resource = $this->_getResource(); $resource->email = $this->_GetPersonasContacts('pwulf')->email; $resource->suppress_notification = $suppress_notification; $persistentResource = Calendar_Controller_Resource::getInstance()->create($resource); // create event with this resource as attender $event = $this->_getEvent(true); $event->attendee->addRecord($this->_createAttender($persistentResource->getId(), Calendar_Model_Attender::USERTYPE_RESOURCE)); self::flushMailer(); $persistentEvent = $this->_eventController->create($event); $this->assertEquals(3, count($persistentEvent->attendee)); $messages = self::getMessages(); if ($suppress_notification) { $this->assertEquals(2, count($messages), 'two mails should be send to attender (invite) + resource'); } else { $this->assertEquals(2, count($messages), 'two mails should be send to current user (resource + attender)'); } // assert user agent // @see 0011498: set user agent header for notification messages $headers = $messages[0]->getHeaders(); $this->assertEquals(Tinebase_Core::getTineUserAgent('Notification Service'), $headers['User-Agent'][0]); }
/** * set headers in mail to be sent * * @param Tinebase_Mail $_mail * @param Felamimail_Model_Account $_account * @param Felamimail_Model_Message $_message */ protected function _setMailHeaders(Zend_Mail $_mail, Felamimail_Model_Account $_account, Felamimail_Model_Message $_message = NULL) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting mail headers'); } // add user agent $_mail->addHeader('User-Agent', Tinebase_Core::getTineUserAgent('Email Client')); // set organization if (isset($_account->organization) && !empty($_account->organization)) { $_mail->addHeader('Organization', $_account->organization); } // set message-id (we could use Zend_Mail::createMessageId() here) if ($_mail->getMessageId() === NULL) { $domainPart = substr($_account->email, strpos($_account->email, '@')); $uid = Tinebase_Record_Abstract::generateUID(); $_mail->setMessageId('<' . $uid . $domainPart . '>'); } if ($_message !== NULL) { if ($_message->flags && $_message->flags == Zend_Mail_Storage::FLAG_ANSWERED && $_message->original_id instanceof Felamimail_Model_Message) { $this->_addReplyHeaders($_message); } // set the header request response if ($_message->reading_conf) { $_mail->addHeader('Disposition-Notification-To', $_message->from_email); } // add other headers if (!empty($_message->headers) && is_array($_message->headers)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding custom headers: ' . print_r($_message->headers, TRUE)); } foreach ($_message->headers as $key => $value) { $value = $this->_trimHeader($key, $value); $_mail->addHeader($key, $value); } } } }