Update and flush the spool email.

@param SpoolEmailInterface $email The spool email
553075
protected function flushEmail(SpoolEmailInterface $email): void
    {
        $email->setSentAt(new \DateTime());
        $this->om->persist($email);
        $this->om->flush();

        if (SpoolEmailStatus::STATUS_SUCCESS === $email->getStatus()) {
            $this->om->remove($email);
            $this->om->flush();
        }

        $this->om->detach($email);
    }
941748
private function validateEmail($email)
    {
        if (!$this->cartHelper->validateEmail($email)) {
            throw new BoltException(
                __('Invalid email: %1', $email),
                null,
                BoltErrorResponse::ERR_UNIQUE_EMAIL_REQUIRED
            );
        }
    }
861104
private function sendContactMail($email, $subject, $message)
    {
        $mailer = oxNew(Email::class);

        if ($mailer->sendContactMail($email, $subject, $message)) {
            $this->_blContactSendStatus = 1;
        } else {
            Registry::getUtilsView()->addErrorToDisplay('ERROR_MESSAGE_CHECK_EMAIL');
        }
    }
710579
public function setRecipients($email)
    {
        if (!is_array($email)) {
            $email = explode(',', $email);
            // trim all values
            array_walk($email, function(&$val) {
                return $val = trim($val);
            });
            // remove empty elements
            $email = array_filter($email);
        }

        foreach ($email as $e) {
            if (!$this->validateHeaderFieldValue($e)) {
                throw new EmailValidationException(__('Recipient address can not contain carriage return or newlines.'));
            }
        }

        $this->_recipients = $email;
    }
285293
public function setSenderEmailAddress($email)
    {
        if (!$this->validateHeaderFieldValue($email)) {
            throw new EmailValidationException(__('Sender Email Address can not contain carriage return or newlines.'));
        }

        $this->_sender_email_address = $email;
    }
1218549
public function setReadReceiptTo($email)
    {
        $email = $this->normalizeEmail($email);
        $this->getSwiftMessage()->setReadReceiptTo($email);

        return $this;
    }
1326785
public function setEmail(string $email): void
	{
		if (!Validators::isEmail($email)) {
			throw new InvalidArgumentException('Value is not valid email');
		}

		/* @var $repository UsersRepository */
		$repository = $this->getRepository();
		$user = $repository->getByEmail($email);
		if ($user !== null && $user !== $this) {
			throw new UniqueConstraintViolationException("Email '$email' exists");
		}
		$this->email = $email;
	}
333291
public void setMailSpoolEnable(Boolean spoolEnable) throws SecurityException {
	checkWriteAccess();
	boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_MAIL);

	if (!hasAccess) throw new SecurityException("no access to update mail server settings");
	Element mail = _getRootElement("mail");
	mail.setAttribute("spool-enable", Caster.toString(spoolEnable, ""));
	// config.setMailSpoolEnable(spoolEnable);
    }
674669
public void setEmail(String email) {

        checkEmail(email);
        if (email != null) {
            email = email.trim();
        }
        m_email = email;
    }
638123
function setSender( $email, $name = false )
    {
        $this->Mail->from = new ezcMailAddress( $email, $name, $this->usedCharset() );
        $this->From = array( 'name' => $name,
                             'email' => $email );
    }
28589
public function setEmail($email)
    {
        $email = is_null($email) ? '' : $email;
        parent::setEmail($email);
        $this->setUsername($email);

        return $this;
    }
1353547
public function sendRestorePassword(string $email, string $hash): void
	{
		$mail = $this->createMail('restorePassword');

		$mail->link = $this->link('Cms:Sign:restorePassword', [
			'hash' => $hash
		]);

		$mail->setSubject('cms.mailing.restorePassword.subject')
			->addTo($email);

		$mail->send();
	}
1113851
public function process($email, $fromName, $fromEmail, $maxAttempts)
    {
        try {
            if ($this->send($email, $fromName, $fromEmail)) {
                $this
                    ->db
                    ->createCommand()
                    ->update(
                        $this->queueTable,
                        ['status' => Email::STATUS_SENT],
                        ['id' => $email['id']]
                    )
                    ->execute();
                return true;
            }

            $attempt = $email['attempt'] + 1;
            if ($attempt <= $maxAttempts) {
                $this
                    ->db
                    ->createCommand()
                    ->update(
                        $this->queueTable,
                        ['attempt' => $attempt],
                        ['id' => $email['id']]
                    )
                    ->execute();
            } else {
                $this
                    ->db
                    ->createCommand()
                    ->update(
                        $this->queueTable,
                        ['status' => Email::STATUS_GAVEUP],
                        ['id' => $email['id']]
                    )
                    ->execute();
            }
        } catch (Exception $e) {
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
1269207
public function send($email = 0)
    {

        if ($email instanceof Email) {
            $this->addEmailToOutbox($email);
        }

        $sent_emails = 0;

        foreach ($this->emails as &$email) {
            
            //all email goes to DEBUG_EMAIL if specified
            if (defined("DEBUG_EMAIL")) {
                $email->debug_info = "\n\nDEBUG MODE: Should be sent to: " . $email->to . " when not in debug mode!";
                $email->debug_info .= "\nDEBUG MODE: Should be sent from: " . $email->from . " when not in debug mode!";

                $email->to = \DEBUG_EMAIL;
                $email->from = \DEBUG_EMAIL;

                if (!empty($email->cc)) {
                    $email->debug_info .= "\nDEBUG MODE: Should be be CCed to: "
                        . implode(", ", $email->cc) . " when not in debug mode!";
                    $email->cc = Array();
                }

                if (!empty($email->bcc)) {
                    $email->debug_info .= "\nDEBUG MODE: Should be be BCCed to: "
                        . implode(", ", $email->bcc) . " when not in debug mode!";
                    $email->bcc = Array();
                }

                $email->body .= $email->debug_info;
                if (!empty($email->body_HTML)) {
                    $email->body_HTML .= nl2br($email->debug_info);
                }
            }
            $email->to = $email->to ? $email->to : null;
            $email->constructMultipartMessage();
            
            //sanitize sender params
            if(preg_match("~<(.*?)>~", $email->from, $match)){
                $sender = $match[1];
            } else {
                $sender = $email->from;
            }
      
            $sender = filter_var($sender, FILTER_SANITIZE_EMAIL);
            $params = sprintf('-f%s', escapeshellcmd($sender));
    
            if (mail($email->to, $email->subject, $email->body, $email->_header_text, $params)) {

                $email->sent = 1;
                $sent_emails++;

                $this->logEmail($email, true);
            } else {
                $this->logEmail($email, false);
            }
        }

        $emails_cnt = count($this->emails);

        $this->emails = Array();

        if ($sent_emails == $emails_cnt) {
            return true;
        } else {
            return false;
        }
    }
1275731
protected function _addRecipientAndHeader($headerName, $email, $name)
    {
        $email = $this->_filterEmail($email);
        $name  = $this->_filterName($name);
        // prevent duplicates
        $this->_recipients[$email] = 1;
        $this->_storeHeader($headerName, $this->_formatAddress($email, $name), true);
    }
483004
public function setEmail($email)
    {
        if (!is_string($email) &&
            filter_var($email, FILTER_VALIDATE_EMAIL)
        ) {
            throw new TypeException(
                '$email must valid and be of type string.'
            );
        }
        $this->email = $email;
    }
344217
public function updateEmail($email) {
		// Make sure we're logged in and have a valid access token.
		if (!$this->auth_token || !$this->username) {
			return FALSE;
		}

		$timestamp = parent::timestamp();
		$result = parent::post(
			'/settings',
			array(
				'action' => 'updateEmail',
				'email' => $email,
				'timestamp' => $timestamp,
				'username' => $this->username,
			),
			array(
				$this->auth_token,
				$timestamp,
			)
		);

		return isset($result->param) && $result->param == $email;
	}