本文整理汇总了PHP中Swift_Mailer::getTransport方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Mailer::getTransport方法的具体用法?PHP Swift_Mailer::getTransport怎么用?PHP Swift_Mailer::getTransport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Mailer
的用法示例。
在下文中一共展示了Swift_Mailer::getTransport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deliver
/**
* Delivers an email
*
* @param MailInterface $mail
* @param Boolean $readReceipt
* @return int the number of messages that have been sent
*
* @throws LogicException In case no Receiver provided
* @throws LogicException In case a read-receipt is asked but no Emitter provided
*/
public function deliver(MailInterface $mail, $readReceipt = false, array $attachments = null)
{
if (!$mail->getReceiver()) {
throw new LogicException('You must provide a receiver for a mail notification');
}
$message = \Swift_Message::newInstance($this->prefix . $mail->getSubject(), $mail->renderHTML(), 'text/html', 'utf-8');
$message->addPart($mail->getMessage(), 'text/plain', 'utf-8');
$message->setFrom($this->emitter->getEmail(), $this->emitter->getName());
$message->setTo($mail->getReceiver()->getEmail(), $mail->getReceiver()->getName());
if ($mail->getEmitter()) {
$message->setReplyTo($mail->getEmitter()->getEmail(), $mail->getEmitter()->getName());
}
if (is_array($attachments)) {
foreach ($attachments as $attachment) {
$message->attach($attachment->As_Swift_Attachment());
}
}
if ($readReceipt) {
if (!$mail->getEmitter()) {
throw new LogicException('You must provide an emitter for a ReadReceipt');
}
$message->setReadReceiptTo([$mail->getEmitter()->getEmail() => $mail->getEmitter()->getName()]);
}
if (!$this->mailer->getTransport()->isStarted()) {
$this->mailer->getTransport()->start();
}
$ret = $this->mailer->send($message);
$this->mailer->getTransport()->stop();
$this->dispatcher->dispatch('phraseanet.notification.sent');
return $ret;
}
示例2: __construct
/**
* Create a new Message.
*
* @param string $name
*/
public function __construct(string $name = null)
{
$this->mailer = self::mailer($name);
if (!self::$listener) {
self::$listener = new Listener();
$this->mailer->getTransport()->registerPlugin(self::$listener);
}
$this->message = new \Swift_Message();
}
示例3: postTask
public function postTask(Worker $worker, array $options = null)
{
if ($worker instanceof MailerAwareWorker) {
if ($this->mailer && $this->transport) {
//Flush the mailer queue, this isn't normally done until the command execution finishes
$this->mailer->getTransport()->getSpool()->flushQueue($this->transport);
$this->transport->stop();
$this->logger->info('Flushed mail queue');
}
}
}
示例4: _flushEmailer
private function _flushEmailer()
{
$transport = $this->_mailer->getTransport();
if (!$transport instanceof \Swift_Transport_SpoolTransport) {
return;
}
$spool = $transport->getSpool();
if (!$spool instanceof \Swift_MemorySpool) {
return;
}
$spool->flushQueue($this->_transport);
}
示例5: send
/**
* Sends a mail.
*
* @ParamType("message", type="Abc\Bundle\JobBundle\Job\Mailer\Message")
* @ParamType("logger", type="@abc.logger")
*
* @param Message $message
* @param LoggerInterface $logger
* @throws \Exception Rethrows exceptions thrown by mailer
*/
public function send(Message $message, LoggerInterface $logger)
{
$logger->debug('Send mail {message}', array('message' => $message));
$mail = $this->mailer->createMessage()->setSubject($message->getSubject())->setFrom($message->getFrom())->setTo($message->getTo());
$mail->addPart($message->getMessage(), 'text/plain');
try {
$this->mailer->send($mail);
$this->mailer->getTransport()->stop();
} catch (\Exception $e) {
$this->mailer->getTransport()->stop();
throw $e;
}
}
示例6: __construct
/**
* Constructor
*
* @param \Swift_Mailer $baseMailer
* @param ContainerInterface $container
*/
public function __construct(\Swift_Mailer $baseMailer, ContainerInterface $container)
{
$this->baseMailer = $baseMailer;
$this->container = $container;
$transport = $this->baseMailer->getTransport();
if ($transport instanceof \Swift_Transport_SpoolTransport) {
$transport = $this->findRealTransport();
if (!$transport) {
$transport = \Swift_NullTransport::newInstance();
}
}
parent::__construct($transport);
}
示例7: process
/**
* {@inheritdoc}
*/
public function process(ConsumerEvent $event)
{
if (!$this->mailer->getTransport()->isStarted()) {
$this->mailer->getTransport()->start();
}
$exception = false;
try {
$this->sendEmail($event->getMessage());
} catch (\Exception $e) {
$exception = $e;
}
$this->mailer->getTransport()->stop();
if ($exception) {
throw new $exception();
}
}
示例8: getTransport
/**
* The Transport used to send messages.
*
* @return \Swift_Transport|\Swift_SmtpTransport
*/
public function getTransport()
{
if ($this->smtpTransport) {
return $this->smtpTransport;
}
return parent::getTransport();
}
示例9: sendSwiftMessage
/**
* Send a Swift Message instance.
*
* @param \Swift_Mime_Message $message
*
* @return int
*/
protected function sendSwiftMessage(Swift_Mime_Message $message) : int
{
if ($this->events) {
$this->events->trigger('events.message.sending', [$message]);
}
try {
return $this->swift->send($message, $this->failedRecipients);
} finally {
$this->swift->getTransport()->stop();
}
}
示例10: sendSwiftMessage
/**
* Send a Swift Message instance.
*
* @param \Swift_Message $message
* @return void
*/
protected function sendSwiftMessage($message)
{
if ($this->events) {
$this->events->fire(new Events\MessageSending($message));
}
try {
return $this->swift->send($message, $this->failedRecipients);
} finally {
$this->swift->getTransport()->stop();
}
}
示例11: sendBatchMail
/**
* @param $fromEmail
* @param BatchEntryMail $batchMail
* @param $doSend
*/
private function sendBatchMail($fromEmail, BatchEntryMail $batchMail, $doSend)
{
$receivers = $batchMail->getReceiverEntries($this->em);
$this->writeOutput('Sending "' . $batchMail->getName() . '" mail to ' . count($receivers) . ' people from ' . $fromEmail);
$spool = $this->mailer->getTransport()->getSpool();
foreach ($receivers as $receiver) {
$this->writeOutput(' -> ' . $receiver->getEmail());
$htmlTemplate = $batchMail->getHtmlTemplate($receiver);
$plainTextTemplate = $batchMail->getPlainTextTemplate($receiver);
$templateData = $batchMail->getTemplateData($receiver, $this->em);
$this->translator->setLocale($receiver->getPool()->getLocale());
$plainTextBody = $this->twig->render($plainTextTemplate, $templateData);
$htmlBody = $this->twig->render($htmlTemplate, $templateData);
$message = \Swift_Message::newInstance()->setSubject($batchMail->getSubject($receiver, $this->translator))->setFrom($fromEmail, $batchMail->getFrom($receiver, $this->translator))->setTo($receiver->getEmail())->setBody($plainTextBody)->addPart($htmlBody, 'text/html');
if ($doSend) {
$this->mailer->send($message);
$spool->flushQueue($this->transport);
$batchMail->handleMailSent($receiver, $this->em);
}
}
}
示例12: forceFlushForCommand
/**
* Force l'envoi des mails en mode Command
* @return integer Number of emails sent
*/
public function forceFlushForCommand()
{
// L'envoi des emails est déclenché sur une réponse du Kernel (inactif en mode commande)
$transport = $this->swift->getTransport();
if (!$transport instanceof \Swift_Transport_SpoolTransport) {
return;
}
$spool = $transport->getSpool();
if (!$spool instanceof \Swift_MemorySpool) {
return;
}
return $spool->flushQueue($this->mailerRealTransport);
}
示例13: modifySmtpSettings
/**
* Modify transport smtp settings
*
* @param UserEmailOrigin $userEmailOrigin
*/
protected function modifySmtpSettings(UserEmailOrigin $userEmailOrigin)
{
$transport = $this->mailer->getTransport();
if ($transport instanceof \Swift_Transport_EsmtpTransport) {
$transport->setHost($userEmailOrigin->getSmtpHost());
$transport->setPort($userEmailOrigin->getSmtpPort());
$transport->setUsername($userEmailOrigin->getUser());
$transport->setPassword($this->encryptor->decryptData($userEmailOrigin->getPassword()));
if ($userEmailOrigin->getSmtpEncryption()) {
$transport->setEncryption($userEmailOrigin->getSmtpEncryption());
}
}
}
示例14: sendSwiftMessage
/**
* Send a Swift Message instance.
*
* @param \Swift_Message $message
* @return void
*/
protected function sendSwiftMessage($message)
{
if ($this->events) {
$this->events->fire('mailer.sending', [$message]);
}
if (!$this->pretending) {
try {
return $this->swift->send($message, $this->failedRecipients);
} finally {
$this->swift->getTransport()->stop();
}
} elseif (isset($this->logger)) {
$this->logMessage($message);
}
}
示例15: __construct
/**
* @param MauticFactory $factory
* @param $mailer
* @param null $from
*/
public function __construct(MauticFactory $factory, \Swift_Mailer $mailer, $from = null)
{
$this->factory = $factory;
$this->mailer = $mailer;
$this->transport = $mailer->getTransport();
try {
$this->logger = new \Swift_Plugins_Loggers_ArrayLogger();
$this->mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($this->logger));
} catch (\Exception $e) {
$this->logError($e);
}
$this->from = !empty($from) ? $from : array($factory->getParameter('mailer_from_email') => $factory->getParameter('mailer_from_name'));
$this->returnPath = $factory->getParameter('mailer_return_path');
// Check if batching is supported by the transport
if ($this->factory->getParameter('mailer_spool_type') == 'memory' && $this->transport instanceof InterfaceTokenTransport) {
$this->tokenizationSupported = true;
}
// Set factory if supported
if (method_exists($this->transport, 'setMauticFactory')) {
$this->transport->setMauticFactory($factory);
}
$this->message = $this->getMessageInstance();
}