/** * 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); } // set mail generator $mail->addHeader('X-MailGenerator', 'Tine 2.0'); // add header to identify mails sent by notification service $mail->addHeader('X-Tine20-Type', 'Notification'); // don't reply to this mail, dear autoresponder ... :) $mail->addHeader('Precedence', 'bulk'); 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.'); } }
/** * set mail body * * @param Tinebase_Mail $_mail * @param Felamimail_Model_Message $_message */ protected function _setMailBody(Tinebase_Mail $_mail, Felamimail_Model_Message $_message) { if ($_message->content_type == Felamimail_Model_Message::CONTENT_TYPE_HTML) { $_mail->setBodyHtml(Felamimail_Message::addHtmlMarkup($_message->body)); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $_mail->getBodyHtml(TRUE)); } } $plainBodyText = $_message->getPlainTextBody(); $_mail->setBodyText($plainBodyText); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $_mail->getBodyText(TRUE)); } }
/** * send lost password mail * * @param string $_username * @return bool * * @todo add more texts to mail views & translate mails */ public function sendLostPasswordMail($_username) { // get full user $fullAccount = Tinebase_User::getInstance()->getFullUserByLoginName($_username); // generate new password $newPassword = $this->generatePassword(); // save new password in user Tinebase_Auth::getInstance()->setPassword($_username, $newPassword, $newPassword); // send lost password mail $mail = new Tinebase_Mail('UTF-8'); $mail->setSubject("New password for Tine 2.0"); // get name from user //$recipientName = $fullAccount->accountFirstName." ".$fullAccount->accountLastName; $recipientName = $fullAccount->accountFullName; // get email from user $recipientEmail = $fullAccount->accountEmailAddress; // get plain and html message from views //-- translate text and insert correct link $view = new Zend_View(); $view->setScriptPath(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'views'); $view->mailTextWelcome = "We generated a new password for you ..."; $view->newPassword = $newPassword; $messagePlain = $view->render('lostpwMailPlain.php'); $mail->setBodyText($messagePlain); $messageHtml = $view->render('lostpwMailHtml.php'); if ($messageHtml !== NULL) { $mail->setBodyHtml($messageHtml); } $mail->addHeader('X-MailGenerator', 'Tine 2.0'); $mail->setFrom('*****@*****.**', 'Tine 2.0 Webmaster'); if (!empty($recipientEmail)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' send lost password email to ' . $recipientEmail); } $mail->addTo($recipientEmail, $recipientName); $mail->send(); return true; } return false; }
/** * set mail body * * @param Tinebase_Mail $_mail * @param Felamimail_Model_Message $_message */ protected function _setMailBody(Tinebase_Mail $_mail, Felamimail_Model_Message $_message) { if ($_message->content_type == Felamimail_Model_Message::CONTENT_TYPE_HTML) { // checking embedded images $embeddedImages = $_mail->processEmbeddedImagesInHtmlBody($_message->body); // now checking embedded signature base64 image $base64Images = $_mail->processEmbeddedImageSignatureInHtmlBody($_message->body); if (count($embeddedImages) > 0) { $_message->body = str_ireplace('src="index.php?method=Felamimail.showTempImage&tempImageId=', 'src="cid:', $_message->body); } if (count($base64Images) > 0) { // there should be only one image in the signature $signature_cid = $_mail->createCid($base64Images[0][1]); $_message->body = preg_replace('/<img id="user-signature-image" alt="[^\\"]+" src="data:image\\/jpeg;base64,[^"]+">/', '<img id="user-signature-image" src="cid:' . $signature_cid . '"/>', $_message->body); } $_mail->setBodyHtml(Felamimail_Message::addHtmlMarkup($_message->body)); if (count($embeddedImages) > 0) { foreach ($embeddedImages as $embeddedImage) { $file = Tinebase_Core::getTempDir() . '/' . $embeddedImage[1]; $image = file_get_contents($file); $_mail->createHtmlRelatedAttachment($image, $embeddedImage[1], 'image/jpg', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $embeddedImage[0]); } } if (count($base64Images) > 0) { // again, there should be only one image in the signature $image = base64_decode($base64Images[0][1]); $_mail->createHtmlRelatedAttachment($image, $signature_cid, 'image/jpg', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $base64Images[0][0]); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $_mail->getBodyHtml(TRUE)); } } $plainBodyText = $_message->getPlainTextBody(); $_mail->setBodyText($plainBodyText); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $_mail->getBodyText(TRUE)); } }