Return the proper mailer.

@throws MailerException
976429
private function getMailer(): \Swift_Mailer
    {
        // If the mailer has already been defined via the constructor, return it.
        if ($this->mailer) {
            return $this->mailer;
        }

        // Get the proper transporter
        switch ($this->config('mailer.transport')) {
            case 'smtp':
                $transport = $this->getSmtpTransport();

                break;

            case 'mail':
                throw new MailerException(
                    "'mail' transport is no longer supported, please use 'smtp' or 'sendmail' transport."
                );

                break;

            default:
                $transport = $this->getSendMailTransport();
        }

        $this->mailer = new \Swift_Mailer($transport);

        return $this->mailer;
    }
15857
protected function _send()
	{
		$message = $this->build_message();
		$return_path = ($this->config['return_path'] !== false) ? $this->config['return_path'] : $this->config['from']['email'];
		if ( ! @mail(static::format_addresses($this->to), $this->subject, $message['body'], $message['header'], '-oi -f '.$return_path))
		{
			throw new \EmailSendingFailedException('Failed sending email');
		}
		return true;
	}
493014
public function sendMail(): void
    {
        if ($this->use_smtp) {
            $mailer = new SmtpMailer([
                'host' => $this->email_host,
                'username' => $this->email_username,
                'password' => $this->email_password,
                'secure' => $this->email_security
            ]);
        } else {
            $mailer = new SendmailMailer();
        }
        $mailer->send($this->email);
    }
499464
protected function emailFactory()
    {
        if (!isset($this->emailFactory)) {
            throw new RuntimeException(sprintf(
                'Email Factory is not defined for [%s]',
                get_class($this)
            ));
        }

        return $this->emailFactory;
    }
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;
    }
743259
protected function getFrom()
    {
        $email = $this->config->get('phpci.email_settings.from_address', self::DEFAULT_FROM);

        if (empty($email)) {
            $email = self::DEFAULT_FROM;
        }

        return $email;
    }
1061438
public function subject($subject)
    {
        try {
            $this->mailer->Subject = $subject;
        } catch (phpmailerException $e) {
            throw new EmailException($e->getMessage(), $e->getCode());
        }

        return $this;
    }
211059
public static function getTransport($mailer)
    {
        $config = Mailer::getConfig()->get($mailer);
        if (!$config) {
            throw new MailerException(MailerException::INVALID_CONFIGURATION, [$mailer]);
        }

        $lib = self::getLibrary($mailer);

        /* @var MailerInterface $libInstance */
        $libInstance = self::factory($lib, MailerInterface::class);

        $instance = $libInstance::getTransport($config);
        if (!self::isInstanceOf($instance, TransportInterface::class)) {
            throw new MailerException(MailerException::TRANSPORT_INTERFACE);
        }

        return $instance;
    }
1310382
public function getSender()
    {
        $sender = $this->createSender();

        $sender->setFrom($this->fromEmail, $this->fromName);

        if ($this->replyToEmail) {
            $sender->setReplyTo($this->replyToEmail);
        }

        return $sender;
    }
500975
public function handler(): Response
    {
        $mailer = new Mailer([
            'driver' => 'smtp',
            'host' => 'host',
            'port' => 0,
            'encryption' => '',
            'username' => 'username',
            'password' => 'password',
            'sender' => 'sender',
            'remark' => ''
        ]);
        if (Mailer::count() === 0) {
            $mailer->default(true);
        }
        $mailer->save();
        $this->log('info', 'Create a mailer [' . $mailer->getSender() . ']');
        return response([
            'id' => $mailer->getId()
        ]);
    }
2985
public function envoyer() {
        $this->setEntete();
        return mail($this->destinataire_email, $this->sujet, $this->message, $this->entete);
    }
1092730
public function getUserEmail()
    {
        return strlen($this->kontakt->getDataValue($this->mailColumn)) ? $this->kontakt->getDataValue($this->mailColumn)
                : $this->adresar->getDataValue($this->mailColumn);
    }
748751
public function getContentIterator()
    {
        // Initializing output array
        $output = new \ArrayIterator();

        // Getting total number of messages
        $maxMessage = $this->storage->countMessages();

        for($i=1; $i<=$maxMessage; $i++) {
            // Getting the message object
            $message = $this->storage->getMessage($i);

            if ($message instanceof \Zend\Mail\Storage\Message) {
                // Adding only unread messages to result iterator
                if ($this->unreadOnly && $message->hasFlag(ZendStorage::FLAG_SEEN)) {
                    continue;
                }

                // Wrapping the result object into an appropriate ResourceInterface instance
                try {
                    $imapMessage = new ImapMessage();
                    $imapMessage->init($this->getName(), $i, $message);
                } catch (\Exception $e) {
                    throw new Exception\SourceGetContentException(
                        sprintf(
                            'Error while getting the content for the resource unique id \'%s\'. Exception is: \'%s\'.',
                            $i,
                            $e->getMessage()
                        )
                    );
                }

                // Adding the wrapping object to the result iterator
                $output->append($imapMessage);
            }
        }

        // Returning the result iterator
        return $output;
    }
868567
protected function getMailer()
    {
        $transport = null;
        if ($this->configurationManager->getSetting('mailer.type') === 'sendmail') {
            $transport = \Swift_SendmailTransport::newInstance($this->configurationManager->getSetting('mailer.sendmailCommand'));
        } else if ($this->configurationManager->getSetting('mailer.type') === 'smtp') {
            $host = $this->configurationManager->getSetting('mailer.smtpHost');
            $port = $this->configurationManager->getSetting('mailer.smtpPort');
            $username = $this->configurationManager->getSetting('mailer.smtpUsername');
            $password = $this->configurationManager->getSetting('mailer.smtpPassword');
            
            $transport = \Swift_SmtpTransport::newInstance($host, $port);
            $transport->setUsername($username);
            $transport->setPassword($password);
        }
        
        if ($transport === null) {
            throw new Exception('No mail transport defined. Please check your configuration.');
        }

        return \Swift_Mailer::newInstance($transport);
    }
559378
public function getMailer()
    {
        if ($this->_mailer === null) {
            $this->_mailer = new PHPMailer();
            $this->_mailer->CharSet = 'UTF-8';
            $this->_mailer->From = $this->from;
            $this->_mailer->FromName = $this->fromName;
            $this->_mailer->isHTML(true);
            $this->_mailer->XMailer = ' ';
            // if sending over smtp, define the settings for the smpt server
            if ($this->isSMTP) {
                if ($this->debug) {
                    $this->_mailer->SMTPDebug = 2;
                }
                $this->_mailer->isSMTP();
                $this->_mailer->SMTPSecure = $this->smtpSecure;
                $this->_mailer->Host = $this->host;
                $this->_mailer->SMTPAuth= $this->smtpAuth;
                $this->_mailer->Username = $this->username;
                $this->_mailer->Password = $this->password;
                $this->_mailer->Port = $this->port;
                $this->_mailer->SMTPOptions = [
                    'ssl' => ['verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true],
                ];
            }
        }

        return $this->_mailer;
    }
1243118
function sender( $convert = true )
    {
//        return $this->Mail->from;
        if ( !$convert )
            return $this->From;

        if ( is_array( $this->From ) )
        {
            $convertedSender = $this->From;
            if ( $this->From['name'] )
            {
                $convertedSender['name'] = $this->convertHeaderText( $this->From['name'] );
            }
            return $convertedSender;
        }
        else if ( is_string( $this->From ) )
        {
            return $this->convertHeaderText( $this->From );
        }

        return $this->From;
    }
828319
protected function registerContactMailer()
    {
        $this->app->bind('contact.mailer', function ($app) {
            $mail = $app['mailer'];
            $home = $app['url']->to('/');
            $path = $app['config']['contact.path'];
            $email = $app['config']['contact.email'];
            $name = $app['config']['app.name'];

            return new Mailer($mail, $home, $path, $email, $name);
        });

        $this->app->alias('contact.mailer', Mailer::class);
    }