protected function doSend($messageID = null, $plain = false) {

		$this->extend('onBeforeDoSend', $this);

		if(!$this->Subject() && $this->getUserTemplate()) {
			$this->setSubject($this->getUserTemplate()->Subject);
		}

		$from = $this->From();
		$config = Config::inst()->forClass('Email');

		if(!$from) {
			if($this->getUserTemplate()) {
				$from = $this->getUserTemplate()->From;
			}
			if(!$from) {
				$from = $config->send_all_emails_from ?: $config->admin_email;
			}

			$this->setFrom($from);
		}


		// Check if a list of Member objects has been given
		if($this->members) {
			foreach($this->members as $m) {
				$this->setTo($m->Email);
				$this->populateTemplate(array(
					'RecipientMember' => $m
				));
			}
		}

		if($this->config()->test_mode) {
			$this->parseVariables($plain);
		}
		else {
			if($plain) {
				parent::sendPlain($messageID);
			}
			else {
				parent::send($messageID);
			}
		}

		$this->extend('onAfterDoSend', $this);

		$this->persist();
	}