Esempio n. 1
0
	/**
	 * Prints the given mail.
	 * 
	 * @param	wcf\system\mail\Mail	$mail
	 * @return	string
	 */
	protected static function printMail(Mail $mail) {
		return	"Date: ".gmdate('r')."\n".
			"To: ".$mail->getToString()."\n".
			"Subject: ".$mail->getSubject()."\n".
			$mail->getHeader()."\n".
			"Attachments: ".print_r($mail->getAttachments(), true)."\n\n".
			$mail->getMessage()."\n\n";
	}
Esempio n. 2
0
	/**
	 * @see	wcf\system\mail\MailSender::sendMail()
	 */
	public function sendMail(Mail $mail) {
		$this->recipients = array();
		if (count($mail->getTo()) > 0) $this->recipients = $mail->getTo();
		if (count($mail->getCC()) > 0) $this->recipients = array_merge($this->recipients, $mail->getCC());
		if (count($mail->getBCC())> 0) $this->recipients = array_merge($this->recipients, $mail->getBCC());
		
		// apply connection
		if ($this->connection === null) {
			$this->connect();
		}
		
		// send mail
		$this->write('MAIL FROM:<'.$mail->getFrom().'>');
		$this->getSMTPStatus();
		if ($this->statusCode != 250) {
			throw new SystemException($this->formatError("wrong from format '".$mail->getFrom()."'"));
		}
		
		// recipients
		$recipientCounter = 0;
		foreach ($this->recipients as $recipient) {
			$this->write('RCPT TO:<'.$recipient.'>');
			$this->getSMTPStatus();
			if ($this->statusCode != 250 && $this->statusCode != 251) {
				if ($this->statusCode < 550) {
					throw new SystemException($this->formatError("wrong recipient format '".$recipient."'"));
				}
				continue;
			}
			$recipientCounter++;
		}
		if (!$recipientCounter) {
			$this->write("RSET");
			return;
		}
		
		// data
		$this->write("DATA");
		$this->getSMTPStatus();
		if ($this->statusCode != 354 && $this->statusCode != 250) {
			throw new SystemException($this->formatError("smtp error"));
		}
		
		$header =
			"Date: ".gmdate('r').Mail::$crlf
			."To: ".$mail->getToString().Mail::$crlf
			."Message-ID: <".md5(uniqid())."@".$_SERVER['SERVER_NAME'].">".Mail::$crlf
			."Subject: ".Mail::encodeMIMEHeader($mail->getSubject()).Mail::$crlf
			.$mail->getHeader();
		
		$this->write($header);
		$this->write("");
		$this->write($mail->getBody());
		$this->write(".");
		
		$this->getSMTPStatus();
		if ($this->statusCode != 250) {
			throw new SystemException($this->formatError("message sending failed"));
		}
	}
Esempio n. 3
0
 /**
  * @see	\wcf\system\mail\MailSender::sendMail()
  */
 public function sendMail(Mail $mail)
 {
     $this->recipients = array();
     if (count($mail->getTo()) > 0) {
         $this->recipients = $mail->getTo();
     }
     if (count($mail->getCC()) > 0) {
         $this->recipients = array_merge($this->recipients, $mail->getCC());
     }
     if (count($mail->getBCC()) > 0) {
         $this->recipients = array_merge($this->recipients, $mail->getBCC());
     }
     // apply connection
     if ($this->connection === null) {
         $this->connect();
     }
     // send mail
     $this->write('MAIL FROM:<' . $mail->getFrom() . '>');
     $this->getSMTPStatus();
     if ($this->statusCode != 250) {
         $this->abort();
         throw new SystemException($this->formatError("wrong from format '" . $mail->getFrom() . "'"));
     }
     // recipients
     $recipientCounter = 0;
     foreach ($this->recipients as $recipient) {
         $this->write('RCPT TO:<' . $recipient . '>');
         $this->getSMTPStatus();
         if ($this->statusCode != 250 && $this->statusCode != 251) {
             if ($this->statusCode < 550) {
                 $this->abort();
                 throw new SystemException($this->formatError("wrong recipient format '" . $recipient . "'"));
             }
             continue;
         }
         $recipientCounter++;
     }
     if (!$recipientCounter) {
         $this->abort();
         return;
     }
     // data
     $this->write("DATA");
     $this->getSMTPStatus();
     if ($this->statusCode != 354 && $this->statusCode != 250) {
         $this->abort();
         throw new SystemException($this->formatError("smtp error"));
     }
     $serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
     if (empty($serverName)) {
         $serverName = gethostname();
         if ($serverName === false) {
             $serverName = 'localhost';
         }
     }
     $header = "Date: " . gmdate('r') . Mail::$lineEnding . "To: " . $mail->getToString() . Mail::$lineEnding . "Message-ID: <" . md5(uniqid()) . "@" . $serverName . ">" . Mail::$lineEnding . "Subject: " . Mail::encodeMIMEHeader($mail->getSubject()) . Mail::$lineEnding . $mail->getHeader();
     $this->write($header);
     $this->write("");
     $lines = explode(Mail::$lineEnding, $mail->getBody());
     foreach ($lines as $line) {
         // 4.5.2 Transparency
         // o  Before sending a line of mail text, the SMTP client checks the
         //    first character of the line.  If it is a period, one additional
         //    period is inserted at the beginning of the line.
         if (StringUtil::startsWith($line, '.')) {
             $line = '.' . $line;
         }
         $this->write($line);
     }
     $this->write(".");
     $this->getSMTPStatus();
     if ($this->statusCode != 250) {
         $this->abort();
         throw new SystemException($this->formatError("message sending failed"));
     }
 }