/** * send mail via transport (smtp) * * @param Zend_Mail $_mail * @param Felamimail_Model_Account $_account * @param boolean $_saveInSent * @param Felamimail_Model_Message $_message * @param array $_nonPrivateRecipients */ protected function _sendMailViaTransport(Zend_Mail $_mail, Felamimail_Model_Account $_account, Felamimail_Model_Message $_message = null, $_saveInSent = false, $_nonPrivateRecipients = array()) { $smtpConfig = $_account->getSmtpConfig(); if (!empty($smtpConfig) && (isset($smtpConfig['hostname']) || array_key_exists('hostname', $smtpConfig))) { $transport = new Felamimail_Transport($smtpConfig['hostname'], $smtpConfig); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { $debugConfig = $smtpConfig; $whiteList = array('hostname', 'username', 'port', 'auth', 'ssl'); foreach ($debugConfig as $key => $value) { if (!in_array($key, $whiteList)) { unset($debugConfig[$key]); } } Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' About to send message via SMTP with the following config: ' . print_r($debugConfig, true)); } Tinebase_Smtp::getInstance()->sendMessage($_mail, $transport); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' successful.'); } // append mail to sent folder if ($_saveInSent) { $this->_saveInSent($transport, $_account, $this->_getAdditionalHeaders($_message)); } if ($_message !== null) { // add reply/forward flags if set if (!empty($_message->flags) && ($_message->flags == Zend_Mail_Storage::FLAG_ANSWERED || $_message->flags == Zend_Mail_Storage::FLAG_PASSED) && $_message->original_id instanceof Felamimail_Model_Message) { Felamimail_Controller_Message_Flags::getInstance()->addFlags($_message->original_id, array($_message->flags)); } // add email notes to contacts (only to/cc) if ($_message->note) { $this->_addEmailNote($_nonPrivateRecipients, $_message->subject, $_message->getPlainTextBody()); } } } else { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not send message, no smtp config found.'); } }
/** * 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.'); } }
/** * send mail via transport (smtp) * * @param Zend_Mail $_mail * @param Expressomail_Model_Account $_account * @param boolean $_saveInSent * @param Expressomail_Model_Message $_message */ protected function _sendMailViaTransport(Zend_Mail $_mail, Expressomail_Model_Account $_account, Expressomail_Model_Message $_message = NULL, $_saveInSent = false) { $smtpConfig = $_account->getSmtpConfig(); if (!empty($smtpConfig) && array_key_exists('hostname', $smtpConfig)) { $transport = new Expressomail_Transport($smtpConfig['hostname'], $smtpConfig); // send message via smtp if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' About to send message via SMTP ...'); } Tinebase_Smtp::getInstance()->sendMessage($_mail, $transport); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' successful.'); } // append mail to sent folder if ($_saveInSent) { $this->_selectSentFolder($_message, $_account); $this->_saveInSent($transport, $_account, $this->_getAdditionalHeaders($_message)); } if ($_message !== NULL) { // add reply/forward flags if set if (!empty($_message->flags) && ($_message->flags == Zend_Mail_Storage::FLAG_ANSWERED || $_message->flags == Zend_Mail_Storage::FLAG_PASSED) && $_message->original_id instanceof Expressomail_Model_Message) { Expressomail_Controller_Message_Flags::getInstance()->addFlags($_message->original_id, array($_message->flags)); } } } else { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not send message, no smtp config found.'); } }
/** * send mail via transport (smtp) * * @param Zend_Mail $_mail * @param Felamimail_Model_Account $_account * @param boolean $_saveInSent * @param Felamimail_Model_Message $_message * @param array $_nonPrivateRecipients */ protected function _sendMailViaTransport(Zend_Mail $_mail, Felamimail_Model_Account $_account, Felamimail_Model_Message $_message = NULL, $_saveInSent = false, $_nonPrivateRecipients = array()) { $smtpConfig = $_account->getSmtpConfig(); if (!empty($smtpConfig) && array_key_exists('hostname', $smtpConfig)) { $transport = new Felamimail_Transport($smtpConfig['hostname'], $smtpConfig); // send message via smtp if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' About to send message via SMTP ...'); } Tinebase_Smtp::getInstance()->sendMessage($_mail, $transport); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' successful.'); } // append mail to sent folder if ($_saveInSent) { $this->_saveInSent($transport, $_account, $_message !== NULL ? array('Bcc' => $_message->bcc) : array()); } if ($_message !== NULL) { // add reply/forward flags if set if (!empty($_message->flags) && ($_message->flags == Zend_Mail_Storage::FLAG_ANSWERED || $_message->flags == Zend_Mail_Storage::FLAG_PASSED) && $_message->original_id instanceof Felamimail_Model_Message) { Felamimail_Controller_Message_Flags::getInstance()->addFlags($_message->original_id, array($_message->flags)); } // add email notes to contacts (only to/cc) if ($_message->note) { $this->_addEmailNote($_nonPrivateRecipients, $_message->subject, $_message->getPlainTextBody()); } } } else { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not send message, no smtp config found.'); } }