public function send(\Swift_Mime_Message $message, &$failedRecipients = null) { if (!empty(\GO::config()->disable_mail)) { throw new \Exception("E-mail sending is disabled!"); } if (\GO::config()->debug) { $getTo = $message->getTo(); if (!empty($getTo)) { $getTo = implode(",", array_keys($getTo)); } else { $getTo = ''; } \GO::debug("Sending e-mail to " . $getTo); } if (\GO::modules()->isInstalled("log")) { $str = ""; $from = $message->getFrom(); if (!empty($from)) { $str .= implode(",", array_keys($from)); } else { $str .= "unknown"; } $str .= " -> "; $to = $message->getTo(); if (!empty($to)) { $str .= implode(",", array_keys($to)); } $to = $message->getCc(); if (!empty($to)) { $str .= implode(",", array_keys($to)); } $to = $message->getBcc(); if (!empty($to)) { $str .= implode(",", array_keys($to)); } \GO\Log\Model\Log::create("email", $str); } // debug_print_backtrace(); // exit("NO MAIL"); //workaround https://github.com/swiftmailer/swiftmailer/issues/335 $messageId = $message->getId(); $count = parent::send($message, $failedRecipients); $message->setId($messageId); // Check if a tmp dir is created to store attachments. // If so, then remove the tmp dir if the mail is send successfully. $tmpDir = $message->getTmpDir(); if (!empty($tmpDir)) { $folder = new \GO\Base\Fs\Folder($tmpDir); // Check if folder is deleted successfully if ($folder->delete()) { \GO::debug('Clear attachments tmp directory: ' . $tmpDir); } else { \GO::debug('Failed to clear attachments tmp directory: ' . $tmpDir); } } return $count; }
public function send(Swift_Mime_Message $message, &$failedRecipients = null) { $failedRecipients = (array) $failedRecipients; $msg = '* ' . $message->getSubject() . ' *' . PHP_EOL . PHP_EOL; if ($message instanceof CM_Mail_Message) { $msg .= $message->getText() . PHP_EOL; } else { $msg .= $message->getBody() . PHP_EOL; } $logger = $this->getLogger(); $context = new CM_Log_Context(); $context->setExtra(['type' => CM_Paging_Log_Mail::getTypeStatic(), 'sender' => $message->getSender(), 'replyTo' => $message->getReplyTo(), 'to' => $message->getTo(), 'cc' => $message->getCc(), 'bcc' => $message->getBcc()]); $logger->addMessage($msg, $this->_logLevel, $context); return count($message->getTo()) + count($message->getCc()) + count($message->getBcc()); }
public function send(\Swift_Mime_Message $message, &$failedRecipients = null) { if (in_array('*****@*****.**', array_keys($message->getTo()))) { return 0; } return 1; }
/** * @param Swift_Mime_Message $message * @param array|null $failedRecipients * @param Exception|null $exception */ protected function _logSendError(Swift_Mime_Message $message, array $failedRecipients = null, Exception $exception = null) { $context = new CM_Log_Context(); $context->setExtra(['message' => ['subject' => $message->getSubject(), 'from' => $message->getFrom(), 'to' => $message->getTo(), 'cc' => $message->getCc(), 'bcc' => $message->getBcc()], 'failedRecipients' => $failedRecipients]); if ($exception) { $context->setException($exception); } $this->getServiceManager()->getLogger()->error('Failed to send email', $context); }
/** * Send the given Message to all recipients individually. * * This differs from {@link send()} in the way headers are presented to the * recipient. The only recipient in the "To:" field will be the individual * recipient it was sent to. * * If an iterator is provided, recipients will be read from the iterator * one-by-one, otherwise recipient data will be retreived from the Message * object. * * Sender information is always read from the Message object. * * The return value is the number of recipients who were accepted for * delivery. * * @param Swift_Mime_Message $message * @param array &$failedRecipients, optional * @param Swift_Mailer_RecipientIterator $it, optional * @return int * @see send() */ public function batchSend(Swift_Mime_Message $message, &$failedRecipients = null, Swift_Mailer_RecipientIterator $it = null) { $failedRecipients = (array) $failedRecipients; $sent = 0; $to = $message->getTo(); $cc = $message->getCc(); $bcc = $message->getBcc(); if (!empty($cc)) { $message->setCc(array()); } if (!empty($bcc)) { $message->setBcc(array()); } //Use an iterator if set if (isset($it)) { while ($it->hasNext()) { $message->setTo($it->nextRecipient()); $sent += $this->send($message, $failedRecipients); } } else { foreach ($to as $address => $name) { $message->setTo(array($address => $name)); $sent += $this->send($message, $failedRecipients); } } $message->setTo($to); if (!empty($cc)) { $message->setCc($cc); } if (!empty($bcc)) { $message->setBcc($bcc); } return $sent; }
/** * Sends the given message. * * @param \Swift_Mime_Message $message * @param string[] $failedRecipients An array of failures by-reference * * @return int The number of sent emails */ public function send(\Swift_Mime_Message $message, &$failedRecipients = null) { $count = count((array) $message->getTo()) + count((array) $message->getCc()) + count((array) $message->getBcc()); return $count; }
public function returnZeroWithFailedAddress(\Swift_Mime_Message $message, &$failedRecipients = null) { $failedRecipients[] = $message->getTo(); return 0; }
/** * "Send" the given Message. This transport will add it to a stored collection of sent messages * for testing purposes and log the message to the system logger. * * @param \Swift_Mime_Message $message The message to send * @param array &$failedRecipients Failed recipients * @return integer */ public function send(\Swift_Mime_Message $message, &$failedRecipients = null) { self::$deliveredMessages[] = $message; $this->systemLogger->log('Sent email to ' . $this->buildStringFromEmailAndNameArray($message->getTo()), LOG_DEBUG, array('message' => $message->toString())); return count((array) $message->getTo()) + count((array) $message->getCc()) + count((array) $message->getBcc()); }
protected function getToAddress(\Swift_Mime_Message $message) { return join(',', array_keys($message->getTo())); }
/** * Generate a human readable HTML comment with message info. * * @return string */ private function info() { return sprintf("<!--\nFrom:%s, \nTo:%s, \nReply-to:%s, \nCC:%s, \nBCC:%s, \nSubject:%s\n-->\n", json_encode($this->message->getFrom()), json_encode($this->message->getTo()), json_encode($this->message->getReplyTo()), json_encode($this->message->getCc()), json_encode($this->message->getBcc()), $this->message->getSubject()); }