Beispiel #1
0
 /**
  * Send an email.
  *
  * @param Message $msg
  * @throws Protocol\Exception
  *         if the the sender address or recpients are undefined.
  * @return bool
  */
 public function send(Message $mail)
 {
     if ($mail->getFrom() === null) {
         throw new Protocol\Exception("The message does not have a from address.");
     }
     if (count($mail->getTo()) + count($mail->getCc()) + count($mail->getBcc()) < 1) {
         throw new Protocol\Exception("The message must have a recipient.");
     }
     if ($mail->getReturnPath() !== null) {
         $reversePath = $mail->getReturnPath();
     } elseif ($mail->getSender() !== null) {
         $reversePath = $mail->getSender();
     } else {
         $reversePath = $mail->getFrom()->email;
     }
     $this->mail($reversePath);
     foreach ($mail->getTo() as $recipient) {
         $this->rcpt($recipient->email);
     }
     foreach ($mail->getCc() as $recipient) {
         $this->rcpt($recipient->email);
     }
     foreach ($mail->getBcc() as $recipient) {
         $this->rcpt($recipient->email);
     }
     $data = $mail->toString();
     $this->data($data);
     $this->close();
     return true;
 }