config = $config; $this->entityManager = $entityManager; $this->serviceFactory = $serviceFactory; $this->transportFactory = $transportFactory; } protected function createSender() : Sender { return new Sender( $this->config, $this->entityManager, $this->serviceFactory, $this->transportFactory, $this->getInboundEmailService(), $this->getSystemInboundEmail() ); } /** * Create a builder. */ public function create() : Sender { return $this->createSender(); } /** * With parameters. * * Available parameters: fromAddress, fromName, replyToAddress, replyToName. */ public function withParams(array $params = []) : Sender { return $this->createSender()->withParams($params); } /** * With specific SMTP parameters. */ public function withSmtpParams(array $params = []) : Sender { return $this->createSender()->withSmtpParams($params); } /** * With specific attachments. */ public function withAttachments(iterable $attachmentList) : Sender { return $this->createSender()->withAttachments($attachmentList); } /** * With envelope options. */ public function withEnvelopeOptions(array $options) : Sender { return $this->createSender()->withEnvelopeOptions($options); } /** * Set a message instance. */ public function withMessage(Message $message) : Sender { return $this->createSender()->message($message); } /** * Whether system STMP is configured. */ public function hasSystemSmtp() : bool { if ($this->config->get('smtpServer')) { return true; } if ($this->getSystemInboundEmail()) { return true; } return false; } protected function getSystemInboundEmail() { $address = $this->config->get('outboundEmailFromAddress'); if (!$this->systemInboundEmailIsCached && $address) { $this->systemInboundEmail = $this->entityManager ->getRepository('InboundEmail') ->where([ 'status' => 'Active', 'useSmtp' => true, 'emailAddress' => $address, ]) ->findOne(); } $this->systemInboundEmailIsCached = true; return $this->systemInboundEmail; } protected function getInboundEmailService() { if (!$this->serviceFactory) return null; if (!$this->inboundEmailService) { $this->inboundEmailService = $this->serviceFactory->create('InboundEmail'); } return $this->inboundEmailService; } /** * Send an email. */ public function send(Email $email) { $this->createSender()->send($email); } /** * Generate a message ID. */ static public function generateMessageId(Email $email) : string { return Sender::generateMessageId($email); } }