/** * @param TransportInterface $transport * @param MailWrappedMessage|Message $message * @return mixed * @throws MailWrapperSetupException */ public static function send(TransportInterface $transport, $message = null) { if (!$message instanceof Message) { $message = MessageTransformerZend::fromWrappedMessage($message); } return $transport->send($message); }
/** * Send a message using the configured transport. * * @param array|Traversable|Message $message */ public function send($message) { if ($message instanceof Message) { $this->transport->send($message); } else { $this->transport->send($this->createMessage($message)); } }
public function send($to, $templateName, array $data = []) { $template = $this->templateBuilder->get($templateName); $message = $this->mailAssembler->assemble($to, $template, $data); $this->mailTransport->send($message); $event = new Event('mail-send:post', $this, ['to' => $to, 'template' => $template, 'message' => $message, 'data' => $data]); $this->eventManager->trigger($event); }
/** * @test * @dataProvider objectsData * @param \stdClass $todo * @param \stdClass $user */ public function it_sends_email_to_the_assignee(\stdClass $todo, \stdClass $user) { $this->todoFinder->expects($this->once())->method('findById')->with($todo->id)->will($this->returnValue($todo)); $this->userFinder->expects($this->once())->method('findById')->with($user->id)->will($this->returnValue($user)); $this->mailer->expects($this->once())->method('send')->with($this->isInstanceOf(Message::class)); $action = $this->action; $action($this->getEvent($todo->id)); }
/** * @param \Zend\Mail\Transport\TransportInterface $transport * @param \Phpro\MailManager\Service\MailMessageCreator $messageCreator * @param \Zend\Mime\Message $mailMessage */ public function it_should_send_a_mail($transport, $messageCreator, $mailMessage) { $mail = $this->getMailStub(); $messageCreator->createMessage($mail)->willReturn($mailMessage); $transport->send(Argument::that(function ($message) use($mail, $mailMessage) { return $message->getBody() == $mailMessage->getWrappedObject() && $message->getTo()->has('*****@*****.**') && $message->getCc()->has('*****@*****.**') && $message->getBcc()->has('*****@*****.**') && $message->getFrom()->has('*****@*****.**') && $message->getReplyTo()->has('*****@*****.**') && $message->getSubject() == $mail->getSubject(); }))->shouldBeCalled(); $this->send($mail); }
/** * @param \Zend\Mail\Transport\TransportInterface $transport * @param \Phpro\MailManager\Service\MailMessageCreator $messageCreator * @param \Zend\Mime\Message $mailMessage */ public function it_should_send_a_mail_with_zend_view_renderer($transport, $messageCreator, $mailMessage) { $mail = $this->getRenderableMailStub(); $messageCreator->createMessage($mail)->willReturn($mailMessage); $transport->send(Argument::that(function ($message) use($mail, $mailMessage) { return $message instanceof Mandrill && $message->getTo()->has('*****@*****.**') && $message->getCc()->has('*****@*****.**') && $message->getBcc()->has('*****@*****.**') && $message->getFrom()->has('*****@*****.**') && $message->getReplyTo()->has('*****@*****.**') && $message->getSubject() == $mail->getSubject() && $message->getOptions() == ['subaccount' => 'test'] && $message->getImages() == [] && $message->getTags() == ['tag1', 'tag2'] && $message->getBody() == $mailMessage->getWrappedObject(); }))->shouldBeCalled(); $this->send($mail); }
/** * @param TodoAssigneeWasReminded $event */ public function __invoke(TodoAssigneeWasReminded $event) { $user = $this->userFinder->findById($event->userId()->toString()); $todo = $this->todoFinder->findById($event->todoId()->toString()); $mail = new Mail\Message(); $mail->setBody("Hello {$user->name}. This a reminder for '{$todo->text}'. Don't be lazy!"); $mail->setFrom('*****@*****.**', 'Proophessor-do'); $mail->addTo($user->email, $user->name); $mail->setSubject('Proophessor-do Todo Reminder'); $this->mailer->send($mail); }
/** * * @param Message $message */ public function send(Message $message) { $mailMessage = MessageConverter::convert($message); foreach ($this->plugins as $plugin) { $plugin->preSend($mailMessage); } $result = $this->transport->send($mailMessage); foreach ($this->plugins as $plugin) { $plugin->postSend($mailMessage, $result); } }
/** * @param TodoWasMarkedAsExpired $event * @return void */ public function __invoke(TodoWasMarkedAsExpired $event) { $todo = $this->todoFinder->findById($event->todoId()->toString()); $user = $this->userFinder->findById($todo->assignee_id); $message = sprintf('Hi %s! Just a heads up: your todo `%s` has expired on %s.', $user->name, $todo->text, $todo->deadline); $mail = new Mail\Message(); $mail->setBody($message); $mail->setEncoding('utf-8'); $mail->setFrom('*****@*****.**', 'Proophessor-do'); $mail->addTo($user->email, $user->name); $mail->setSubject('Proophessor-do Todo expired'); $this->mailer->send($mail); }
/** * Configures specific transport options * @param TransportInterface $transport * @param MailOptions $mailOptions */ protected function setupSpecificConfig(TransportInterface $transport, MailOptions $mailOptions) { if ($transport instanceof Smtp) { $connConfig = array('username' => $mailOptions->getSmtpUser(), 'password' => $mailOptions->getSmtpPassword()); // Check if SSL should be used if ($mailOptions->getSsl() !== false) { $connConfig['ssl'] = $mailOptions->getSsl(); } // Set SMTP transport options $transport->setOptions(new SmtpOptions(array('host' => $mailOptions->getServer(), 'port' => $mailOptions->getPort(), 'connection_class' => $mailOptions->getConnectionClass(), 'connection_config' => $connConfig))); } elseif ($transport instanceof File) { $transport->setOptions(new FileOptions(array('path' => $mailOptions->getFilePath(), 'callback' => $mailOptions->getFileCallback()))); } }
/** * @param Message $message */ public function send(Message $message) { try { if (!$this->transport) { try { $this->transport = $this->getServiceLocator()->get(TransportInterface::class); } catch (ServiceNotFoundException $ex) { $this->transport = new Sendmail(); } } $this->transport->send($message); } catch (RuntimeException $e) { $this->logger()->error($e->getMessage(), $e->getTrace()); } }
public function send(Message $message, array $attachments = array()) { if ($this->getConfiguration()->getSendAllMailsToBcc() !== null) { $message->addBcc($this->getConfiguration()->getSendAllMailsToBcc()); } if ($this->getConfiguration()->getSendAllMailsTo() != null) { $message->setTo($this->getConfiguration()->getSendAllMailsTo()); } $content = $message->getBody(); $bodyMessage = new \Zend\Mime\Message(); $multiPartContentMessage = new \Zend\Mime\Message(); $text = new Part(strip_tags($content)); $text->type = Mime::TYPE_TEXT; $text->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $multiPartContentMessage->addPart($text); $html = new Part($content); $html->type = Mime::TYPE_HTML; $html->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $html->charset = 'utf-8'; $multiPartContentMessage->addPart($html); $multiPartContentMimePart = new Part($multiPartContentMessage->generateMessage()); $multiPartContentMimePart->charset = 'UTF-8'; $multiPartContentMimePart->type = 'multipart/alternative'; $multiPartContentMimePart->boundary = $multiPartContentMessage->getMime()->boundary(); $bodyMessage->addPart($multiPartContentMimePart); foreach ($attachments as $attachment) { $bodyMessage->addPart($attachment); } $message->setBody($bodyMessage); $message->setEncoding("UTF-8"); $this->transport->send($message); }
/** * Create a support ticket * * @param string $email * @param string $title * @param string $content * @param array $attributes */ public function createTicket($email, $title, $content, array $attributes = array()) { if ($this->subjectPrefix) { $title = $this->subjectPrefix . ' ' . $title; } // Figure out to address $toEmail = null; $toName = null; if (is_array($this->to)) { $toEmail = $this->to[0]; if (isset($this->to[1])) { $toName = $this->to[1]; } } else { $toEmail = $this->to; } // Figure out from address $fromEmail = $email; $fromName = null; if ($this->from) { if (is_array($this->from)) { $fromEmail = $this->from[0]; if (isset($this->from[1])) { $fromName = $this->from[1]; } } else { $fromEmail = $this->from; } } $message = new Message(); $message->setSubject($title)->addTo($toEmail, $toName)->setFrom($fromEmail, $fromName)->setReplyTo($email)->setBody($content); $message->getHeaders()->addHeaderLine('content-type', 'text/plain; charset="UTF-8"'); $this->transport->send($message); }
/** * @param TodoAssigneeWasReminded $event */ public function __invoke(TodoAssigneeWasReminded $event) { $user = null; $this->queryBus->dispatch(new GetUserById($event->userId()->toString()))->then(function ($result) use(&$user) { $user = $result; }); $todo = null; $this->queryBus->dispatch(new GetTodoById($event->todoId()->toString()))->then(function ($result) use(&$todo) { $todo = $result; }); $mail = new Mail\Message(); $mail->setBody("Hello {$user->name}. This a reminder for '{$todo->text}'. Don't be lazy!"); $mail->setFrom('*****@*****.**', 'Proophessor-do'); $mail->addTo($user->email, $user->name); $mail->setSubject('Proophessor-do Todo Reminder'); $this->mailer->send($mail); }
/** * Send email * * @access public */ public function execute() { $payload = $this->getContent(); $from = $payload['from']; $to = $payload['to']; $subject = $payload['subject']; $body = $payload['body']; $message = new Message(); $message->addTo($to)->addFrom($from)->setSubject($subject)->setBody($body); if (array_key_exists('bcc', $payload)) { $bcc = $payload['bcc']; $message->addBcc($bcc); } if (array_key_exists('cc', $payload)) { $cc = $payload['cc']; $message->addCc($cc); } $this->transport->send($message); }
/** * Get the mail transport object. * * @return \Zend\Mail\Transport\TransportInterface */ public function getTransport() { // Create transport if it does not already exist: if (is_null($this->transport)) { $settings = array('host' => $this->config->Mail->host, 'port' => $this->config->Mail->port); if (isset($this->config->Mail->username) && isset($this->config->Mail->password)) { $settings['connection_class'] = 'login'; $settings['connection_config'] = array('username' => $this->config->Mail->username, 'password' => $this->config->Mail->password); } $this->transport = new Smtp(); $this->transport->setOptions(new SmtpOptions($settings)); } return $this->transport; }
/** * Get message transport * * @return \Zend\Mail\Transport\TransportInterface */ protected static function getMessageTransport() { if (!self::$messageTransport) { // should we use SMTP? if ((int) ApplicationSettingService::getSetting('application_use_smtp')) { self::$messageTransport = new SmtpTransport(); // get connection config $connectionConfig = []; // get smtp ssl if (null != ($smtpSsl = ApplicationSettingService::getSetting('application_smtp_ssl'))) { $connectionConfig['ssl'] = $smtpSsl; } // get smtp user if (null != ($smtpUsername = ApplicationSettingService::getSetting('application_smtp_user'))) { $connectionConfig['username'] = $smtpUsername; } // get smtp password if (null != ($smtpPassword = ApplicationSettingService::getSetting('application_smtp_password'))) { $connectionConfig['password'] = $smtpPassword; } // set global options $globalOptions = []; // get smtp host if (null != ($smtpHost = ApplicationSettingService::getSetting('application_smtp_host'))) { $globalOptions['host'] = $smtpHost; } // get connection class if (null != ($smtpConnection = ApplicationSettingService::getSetting('application_smtp_login'))) { $globalOptions['connection_class'] = $smtpConnection; } // get connection config if ($connectionConfig) { $globalOptions['connection_config'] = $connectionConfig; } // get smtp port if (null != ($smtpPort = ApplicationSettingService::getSetting('application_smtp_port'))) { $globalOptions['port'] = $smtpPort; } $options = new SmtpOptions($globalOptions); self::$messageTransport->setOptions($options); return self::$messageTransport; } self::$messageTransport = new SendmailTransport(); } return self::$messageTransport; }
/** * Sends the mail * @return ResultInterface * @throws MailException */ public function send() { $result = new MailResult(); try { // Trigger pre send event $this->getEventManager()->triggerEvent($this->createMailEvent()); // Attach files before sending the email $this->attachFiles(); // Try to send the message $this->transport->send($this->message); // Trigger post send event $this->getEventManager()->triggerEvent($this->createMailEvent(MailEvent::EVENT_MAIL_POST_SEND, $result)); } catch (\Exception $e) { $result = $this->createMailResultFromException($e); // Trigger send error event $this->getEventManager()->triggerEvent($this->createMailEvent(MailEvent::EVENT_MAIL_SEND_ERROR, $result)); // If the exception produced is not a Zend\Mail exception, rethrow it as a MailException if (!$e instanceof ZendMailException) { throw new MailException('An non Zend\\Mail exception occurred', $e->getCode(), $e); } } return $result; }
/** * Sends mail to recipient(s) if log entries are present. Note that both * plaintext and HTML portions of email are handled here. */ public function shutdown() { // If there are events to mail, use them as message body. Otherwise, // there is no mail to be sent. if (empty($this->eventsToMail)) { return; } if ($this->subjectPrependText !== null) { // Tack on the summary of entries per-priority to the subject // line and set it on the Zend\Mail object. $numEntries = $this->getFormattedNumEntriesPerPriority(); $this->mail->setSubject("{$this->subjectPrependText} ({$numEntries})"); } // Always provide events to mail as plaintext. $this->mail->setBody(implode('', $this->eventsToMail)); // Finally, send the mail. If an exception occurs, convert it into a // warning-level message so we can avoid an exception thrown without a // stack frame. try { $this->transport->send($this->mail); } catch (TransportException\ExceptionInterface $e) { trigger_error("unable to send log entries via email; " . "message = {$e->getMessage()}; " . "code = {$e->getCode()}; " . "exception class = " . get_class($e), E_USER_WARNING); } }
/** * @param MailInterface $mail */ public function send(MailInterface $mail) { $message = $this->createMessage($mail); $this->transport->send($message); }
/** * @param Message $message */ public function send(Message $message) { $this->checkFrom($message); return $this->transport->send($message); }
/** * @param MemberInformation $fromMember * @param MemberInformation $toMember * @param Money $amount * @param DateTime $occurredOn */ public function sendDepositReceivedEmail(MemberInformation $fromMember, MemberInformation $toMember, Money $amount, DateTime $occurredOn) { $message = new Message(); $message->setFrom('*****@*****.**')->setTo($toMember->email()->address())->setSubject('You have received a deposit')->setBody($this->template->render('email/deposit.html', ['fromMember' => $fromMember, 'toMember' => $toMember, 'amount' => $amount, 'occurredOn' => $occurredOn])); $this->mailTransport->send($message); }
/** * @param TransportInterface $transport * @return TransportInterface */ protected function setupTransportConfig(TransportInterface $transport) { if ($transport instanceof Smtp) { $transport->setOptions($this->mailOptions->getSmtpOptions()); } elseif ($transport instanceof File) { $transport->setOptions($this->mailOptions->getFileOptions()); } return $transport; }