Send an email from notification

@param MailLog $mail

@return void
330124
public function sendNotificationEmail($mail, $from=null)
    {
        $templateName = 'CoreBundle:Email:notification.email.html.twig';

        $context = array(
            'mail' => $mail
        );
        
        if(is_null($from)){
            $this->sendMessage(
                $templateName, 
                $context,  
                $mail->getSender(),
                $mail->getRecipient(),
                $mail->getAttachment()
                );
        }else{
            $this->sendMessage(
                $templateName, 
                $context,  
                $from,
                $mail->getRecipient(),
                $mail->getAttachment()
                );
        }
        
    }
925241
protected function sendEmail($email,$subject,$message)
	{
		$headers=$this->getHeaders();
		if($this->utf8)
		{
			$headers[]="MIME-Version: 1.0";
			$headers[]="Content-Type: text/plain; charset=UTF-8";
			$subject='=?UTF-8?B?'.base64_encode($subject).'?=';
		}
		if(($from=$this->getSentFrom())!==null)
		{
			$matches=array();
			preg_match_all('/([^<]*)<([^>]*)>/iu',$from,$matches);
			if(isset($matches[1][0],$matches[2][0]))
			{
				$name=$this->utf8 ? '=?UTF-8?B?'.base64_encode(trim($matches[1][0])).'?=' : trim($matches[1][0]);
				$from=trim($matches[2][0]);
				$headers[]="From: {$name} <{$from}>";
			}
			else
				$headers[]="From: {$from}";
			$headers[]="Reply-To: {$from}";
		}
		mail($email,$subject,$message,implode("\r\n",$headers));
	}
279445
public function setReplyTo($email)
    {
        if ($this->isValidEmail($email) === true) {
            $this->reply_to = $email;
        } else {
            return false;
        }
    }
1102489
public function send(Email $email) {
		if (!empty($this->_config['queue'])) {
			$this->_config = $this->_config['queue'] + $this->_config;
			$email->setConfig((array)$this->_config['queue'] + ['queue' => []]);
			unset($this->_config['queue']);
		}

		$settings = [
			'from' => [$email->getFrom()],
			'to' => [$email->getTo()],
			'cc' => [$email->getCc()],
			'bcc' => [$email->getBcc()],
			'charset' => [$email->getCharset()],
			'replyTo' => [$email->getReplyTo()],
			'readReceipt' => [$email->getReadReceipt()],
			'returnPath' => [$email->getReturnPath()],
			'messageId' => [$email->getMessageId()],
			'domain' => [$email->getDomain()],
			'headers' => [$email->getHeaders()],
			'headerCharset' => [$email->getHeaderCharset()],
			'theme' => [$email->getTheme()],
			'profile' => [$email->getProfile()],
			'emailFormat' => [$email->getEmailFormat()],
			'subject' => method_exists($email, 'getOriginalSubject') ? [$email->getOriginalSubject()] : [$email->getSubject()],
			'transport' => [$this->_config['transport']],
			'attachments' => [$email->getAttachments()],
			'template' => [$email->getTemplate()],
			'layout' => [$email->getLayout()],
			'viewVars' => [$email->getViewVars()]
		];

		foreach ($settings as $setting => $value) {
			if (array_key_exists(0, $value) && ($value[0] === null || $value[0] === [])) {
				unset($settings[$setting]);
			}
		}

		$QueuedJobs = $this->getQueuedJobsModel();
		$result = $QueuedJobs->createJob('Email', ['settings' => $settings]);
		$result['headers'] = '';
		$result['message'] = '';

		return $result->toArray();
	}
1000343
public function sendMessage($level, $message)
    {
        $mail = new Message($this->from);

        $mail->setTo($this->to);
        $mail->setText(ucfirst($level).': '.$message, $this->type);

        /** @var ITransport $transport */
        $transport = (new TransportInjector)->build();
        $transport->send($mail);
    }
623040
public function log($level, $message, array $context = []) {
        if ($this->_emailsSent > $this->maxEmailsPerRun){
            return; // skip all checks if max number was already reached
        }
        if (in_array($level, $this->visibleLevels) && $this->emailAddress) {
            $mailer = $this->mailerClass;
            $mailer::get()->send($this->emailAddress, $this->getSubject($level, isset($context['fromClass']) ? $context['fromClass'] : ''), $this->getMessage($level, $message, $context));
            if ($this->_emailsSent++ > $this->maxEmailsPerRun){
                if ($this->dieWhenMaxEmailsIsReached) {
                    die(); // too many errors; 
                }
            }
        }
    }
374580
public function send($notifiable, Notification $notification)
    {
        $message = $notification->toMessagebird($notifiable);

        if (is_string($message)) {
            $message = MessagebirdMessage::create($message);
        }

        if ($to = $notifiable->routeNotificationFor('messagebird')) {
            $message->setRecipients($to);
        }

        $this->client->send($message);
    }
461812
public function send(): void
	{
		/**
		 * Template variables..
		 */
		$this->template->mailData = $this->mailData;

		/**
		 * Stick to convention that Email:
		 * 		/FooMail.php	
		 * 
		 * will have template with path of:
		 * 		/templates/FooMail.latte
		 */
		$mailClassReflection = new \ReflectionClass($this);
		$templateName = $mailClassReflection->getShortName();

		$this->template->setFile(sprintf(
			'%s/templates/%s.latte',
			dirname($mailClassReflection->getFilename()),
			$templateName
		));

		/**
		 * Set body/html body
		 */
		if (version_compare(Engine::VERSION, '2.4.0', '>=')) {
			$this->template->getLatte()->addProvider('uiControl', $this->linkGenerator);
		} else {
			$this->template->_control = $this->linkGenerator;
		}

		$this->message->setHtmlBody((string) $this->template, $this->mailImagesBasePath);

		/**
		 * In case mail sending in on, send message
		 */
		if ($this->config === MailingExtension::CONFIG_BOTH || $this->config === MailingExtension::CONFIG_SEND) {
			$this->mailer->send($this->message);
		}

		/**
		 * In case mail logging is turned on, log message
		 */
		if ($this->config === MailingExtension::CONFIG_LOG || $this->config === MailingExtension::CONFIG_BOTH) {
			$this->logger->log($templateName, $this->message);
		}
	}
309438
private function handleNotification(Notification $notification)
    {
        if (empty($notification->targetTypes())) {
            return;
        }
        $objectsByTypes = [];
        $numTotal = 0;
        foreach ($notification->targetTypes() as $objType) {
            $objType = trim($objType);
            $objects = $this->updatedObjects($objType);
            $num = count($objects);
            if ($num == 0) {
                continue;
            }
            $obj = [];
            $obj['objects'] = $objects;
            $obj['num'] = $num;
            $obj['type'] = $objType;
            $obj['typeLabel'] = isset($objects[0]['targetTypeLabel']) ? $objects[0]['targetTypeLabel'] : $objType;

            $objectsByTypes[$objType] = $obj;
            $numTotal += $num;
        }
        $this->sendEmail($notification, $objectsByTypes, $numTotal);
    }
855098
public function send(Mail\Message $message)
    {
        $this->getMandrillClient();

        $body = $message->getBody();
        $attachments = [];

        switch (true) {
            case $body instanceof Message:
                $bodyHtml = $this->getHtmlPart($body);
                $bodyText = $this->getTextPart($body);
                $attachments = $this->getAttachments($body);
                break;
            case is_string($body):
                $bodyHtml = $body;
                $bodyText = $message->getBodyText();
                break;
            case is_object($body):
                $bodyHtml = $body->__toString();
                $bodyText = $message->getBodyText();
                break;
            default:
                throw new Exception\InvalidArgumentException(
                    sprintf(
                        '"%s" expectes a body that is a string, an object or a Zend\Mime\Message; received "%s"',
                        __METHOD__,
                        is_object($body) ? get_class($body) : gettype($body)
                    )
                );
                break;
        }

        $message = [
            'html' => $bodyHtml,
            'text' => $bodyText,
            'subject' => $message->getSubject(),
            'from_email' => $message->getFrom()->current()->getEmail(),
            'from_name' => $message->getFrom()->current()->getName(),
            'to' => array_merge(
                $this->mapAddressListToArray($message->getTo(), 'to'),
                $this->mapAddressListToArray($message->getCc(), 'cc'),
                $this->mapAddressListToArray($message->getBcc(), 'bcc')
            ),
            'headers' => $message->getHeaders()->toArray(),
            'subaccount' => $this->options->getSubAccount(),
            'attachments' => $attachments
        ];

        return $this->mandrillClient->messages->send($message);
    }
623122
protected function addHeaders(Email $notification, \Swift_Message $email)
    {
        $headers = $email->getHeaders();

        foreach ($notification->getAdditionalHeaders() as $key => $value) {
            if ($value instanceof \DateTime) {
                $headers->addDateHeader($key, $value);
            } else {
                $headers->addTextHeader($key, $value);
            }
        }
    }
1214367
public function send( Net_Mail $mail )
	{
		$mail->setHeaderPair( 'X-Mailer', $this->mailer );
		$delim		= Net_Mail::$delimiter;
		$date		= date( "D, d M Y H:i:s O", time() );
		$subject	= "=?UTF-8?B?".base64_encode( $mail->getSubject() )."?=";
		$conn		= fsockopen( $this->host, $this->port, $errno, $errstr, 5 );
		if( !$conn )
			throw new RuntimeException( 'Connection to SMTP server "'.$this->host.':'.$this->port.'" failed' );
		if( !$mail->getSender() )
			throw new RuntimeException( 'No mail sender set' );
		if( !$mail->getReceiver() )
			throw new RuntimeException( 'No mail receiver set' );
		if( !$mail->getBody() )
			throw new RuntimeException( 'No mail body set' );
		try{
			$this->checkResponse( $conn );
			$this->sendChunk( $conn, "HELO ".$this->host );
			$this->checkResponse( $conn );
			if( $this->isSecure ){
				$this->sendChunk( $conn, "STARTTLS" );
				$this->checkResponse( $conn );
				stream_socket_enable_crypto( $conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT );
			}
			if( $this->username && $this->password ){
				$this->sendChunk( $conn, "AUTH LOGIN" );
				$this->checkResponse( $conn );
				$this->sendChunk( $conn, base64_encode( $this->username ) );
				$this->checkResponse( $conn );
				$this->sendChunk( $conn, base64_encode( $this->password ) );
				$this->checkResponse( $conn );
			}
			$this->sendChunk( $conn, "MAIL FROM: ".$mail->getSender() );
			$this->sendChunk( $conn, "RCPT TO: ".$mail->getReceiver() );
			$this->sendChunk( $conn, "DATA" );
			$this->checkResponse( $conn );
			$this->sendChunk( $conn, "Date: ".$date );
			$this->sendChunk( $conn, "Subject: ".$subject );
			$this->sendChunk( $conn, "To: <".$mail->getReceiver().">" );
			foreach( $mail->getHeaders()->getFields() as $header )
				$this->sendChunk( $conn, $header->toString() );
			$this->sendChunk( $conn, $delim.$mail->getBody() );
			$this->checkResponse( $conn );
			$this->sendChunk( $conn, '.' );
			$this->checkResponse( $conn );
			$this->checkResponse( $conn );
			$this->sendChunk( $conn, "QUIT" );
			$this->checkResponse( $conn );
			fclose( $conn );
		}
		catch( Exception $e ){
			fclose( $conn );
			throw new RuntimeException( $e->getMessage(), $e->getCode(), $e->getPrevious() );
		}
	}
1305067
public function setEmail($email, $defaultEmail = null)
    {
        if (!empty($email)) {
            $this->email = $email;
        } else if (!empty($defaultEmail)) {
            $this->email = $defaultEmail;
            if (substr($this->email, 0, 1) == '@') {
                $this->email = $this->getId() . $this->email;
            }
        } else {
            $this->email = '';
        }
    }
595898
public function send(string $notifiable, Notification $notification)
    {
        $channelResult = $notification->toMail($notifiable);
        $messages = is_array($channelResult) ? $channelResult : [$channelResult];

        foreach ($messages as $message) {
            if (! $message instanceof Message) {
                throw new \Exception("Message needs to be an instance of craft\mail\Message");
            }

            $message->send();
        }
    }
288482
private function sendEmail($to = '', $subject = '', $messageText = '')
    {
        $transport = $this->getServiceLocator()->get('mail.transport');
        $message = new Message();
            
        $message->addTo($to)
                ->addFrom($this->getOptions()->getSenderEmailAdress())
                ->setSubject($subject)
                ->setBody($messageText);

        $transport->send($message);
    }
1276873
public function send(PHPMailer $mail)
    {
        if ($template = $this->getOption('subjectTemplate')) {
            /** @var string $template */
            $mail->Subject = Translator::translate($template, $mail->Subject);
        }

        if (!$mail->send()) {
            // Why you don't use "Exception mode" of PHPMailer
            // Because we need our Exception in any case
            throw new MailerException('Error mail send: ' . $mail->ErrorInfo);
        }

        return true;
    }
1314883
public function sendNotification()
    {
        if (($from = self::config()->get('mail_sender')) && empty($from)) {
            $from = Config::inst()->get('Email', 'admin_email');
        }

        if (($to = self::config()->get('mail_receiver')) && empty($to)) {
            $to = Config::inst()->get('Email', 'admin_email');
        }

        $email = new Email();
        $email->setSubject(_t(
            'NotificationMail.TITLE',
            'Nieuwe reservering voor {event}',
            null, array('event' => $this->Event()->Title)
        ));

        $email->setFrom($from);
        $email->setTo($to);
        $email->setTemplate('NotificationMail');
        $email->populateTemplate($this);
        $this->extend('updateNotificationMail', $email);
        return $email->send();
    }