Operation sendTemplateAsync

Send a template

@param  int $templateId Id of the template (required)
@param  \SendinBlue\Client\Model\SendEmail $sendEmail (required)

@throws \InvalidArgumentException
@return \GuzzleHttp\Promise\PromiseInterface
327610
public function sendTemplateAsync($templateId, $sendEmail)
    {
        return $this->sendTemplateAsyncWithHttpInfo($templateId, $sendEmail)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }
872055
public function render(string $templateID, string $language, \Swift_Mime_SimpleMessage &$message)
    {
        // Find Template
        $template = $this->entityManager
            ->getRepository(MailTemplate::class)
            ->findOneBy(['templateId' => $templateID, 'status' => true, 'language' => $language]);

        if ((null === $template) && ($language !== $this->defaultLanguage)) {
            return $this->render($templateID, $this->defaultLanguage, $message);
        }

        // Render Template
        if (null !== $template) {
            // Render Body
            try {
                $message->setBody(
                    $this->twig->createTemplate($template->getTemplate())->render(unserialize($message->getBody())),
                    $message->getContentType(),
                    $message->getCharset());
            } catch (\Exception $e) {
            }

            // Set Header
            if (!empty($template->getFromName()) && !empty($template->getFromEmail())) {
                $message->setFrom($template->getFromEmail(), $template->getFromName());
            }

            // Set Subject
            if (!empty($template->getSubject())) {
                $message->setSubject($template->getSubject());
            }

            return true;
        }

        return false;
    }
609671
public function sendCustomerConfirmation(
        $recipient,
        ApiOrderInterface $apiOrder,
        ContactInterface $customerContact = null
    ) {
        if (!$this->sendEmailConfirmationToCustomer) {
            return false;
        }

        return $this->sendConfirmationEmail(
            $recipient,
            $apiOrder,
            $this->templateCustomerConfirmationPath,
            $customerContact
        );
    }
711852
protected function renderEmail(
        $subject,
        $receiverEmail,
        array $context = []
    ) {
        $message = Swift_Message::newInstance()
            ->setSubject($subject)
            ->setFrom($this->fromEmail)
            ->setTo($receiverEmail)
            ->setContentType('text/html')
            ->setBody(
                $this->templatingEngine->render(
                    $this->template,
                    array_merge(
                        $context,
                        ['layout' => $this->layout]
                    )
                )
            );

        $this
            ->mailer
            ->send($message);

        return $this;
    }
1002684
def send_mail_template(subject, template, addr_from, recipient_list,
                       fail_silently=False, attachments=None, context=None,
                       connection=None, headers=None):
    

    if context is None:
        context = {}

    # Loads a template passing in vars as context.
    def render(ext):
        name = "email_extras/%s.%s" % (template, ext)
        return loader.get_template(name).render(context)

    send_mail(subject, render("txt"), addr_from, recipient_list,
              fail_silently=fail_silently, attachments=attachments,
              html_message=render("html"), connection=connection,
              headers=headers)
591372
public function send(array $message, $template = false, array $templateVars = [])
    {
        // render the body from the template
        if ($template) {
            $message = $this->messageFromTemplate($message, $template, $templateVars);
        }

        // set missing from information
        if (!isset($message['from_email'])) {
            $message['from_email'] = array_value($this->settings, 'from_email');
        }

        if (!isset($message['from_name'])) {
            $message['from_name'] = array_value($this->settings, 'from_name');
        }

        return $this->driver->send($message);
    }
1137944
public function send(Message $message, $templateName = '', $templateContent = array(), $async = false, $ipPool = null, $sendAt = null)
    {
        if ($this->disableDelivery) {
            return false;
        }

        if (strlen($message->getFromEmail()) == 0) {
            $message->setFromEmail($this->defaultSender);
        }

        if (strlen($message->getFromName()) == 0 && null !== $this->defaultSenderName) {
            $message->setFromName($this->defaultSenderName);
        }

        if (strlen($message->getSubaccount()) == 0 && null !== $this->subaccount) {
            $message->setSubaccount($this->subaccount);
        }

        if (!empty($templateName)) {
            return $this->service->messages->sendTemplate($templateName, $templateContent, $message->toArray(), $async, $ipPool, $sendAt);
        }

        return $this->service->messages->send($message->toArray(), $async, $ipPool, $sendAt);
    }
1097294
public function sendOrderMail(
        $recipient,
        $templatePath,
        $data = array(),
        ApiOrderInterface $apiOrder = null,
        $blindCopyRecipients = array()
    ) {
        $tmplData = array_merge(
            $data,
            array(
                'footerTxt' => $this->templateFooterTxtPath,
                'footerHtml' => $this->templateFooterHtmlPath,
            )
        );

        $template = $this->twig->loadTemplate($templatePath);
        $subject = $template->renderBlock('subject', $tmplData);

        $emailBodyText = $template->renderBlock('body_text', $tmplData);
        $emailBodyHtml = $template->renderBlock('body_html', $tmplData);

        /** @var \Swift_Message $message */
        $message = \Swift_Message::newInstance()
            ->setSubject($subject)
            ->setFrom($this->emailFrom)
            ->setTo($recipient)
            ->setBody($emailBodyText, 'text/plain')
            ->addPart($emailBodyHtml, 'text/html');
        
        // add blind copy recipients
        foreach ($blindCopyRecipients as $bcc) {
            $message->addBcc($bcc);
        }

        // add pdf if order is supplied
        if ($apiOrder) {
            $pdf = $this->pdfManager->createOrderConfirmation($apiOrder);
            $pdfFileName = $this->pdfManager->getPdfName($apiOrder);
            // now send mail
            $attachment = \Swift_Attachment::newInstance()
                ->setFilename($pdfFileName)
                ->setContentType('application/pdf')
                ->setBody($pdf);
            $message->attach($attachment);
        }

        $failedRecipients = array();
        $this->mailer->send($message, $failedRecipients);

        if (count($failedRecipients) > 0) {
            $this->writeLog('Could not send mail to the following recipients: ' . join(', ', $failedRecipients));

            return false;
        }

        return true;
    }
418881
def sendTemplate(mailer, sender, recipient, template, context, hook=_nop):
    
    headers, parts = template.evaluate(context)
    headers["From"] = sender
    headers["To"] = recipient
    hook(headers, parts)

    content = mime.buildMessage(headers, parts)
    return mailer.send(sender, recipient, content)
136419
function sendMail (template, locals, options, callback) {
  var self = this
  this.render(template, locals, function (err, html, text) {
    if (err) { return callback(err) }

    self.transport.sendMail({
      from: options.from || defaultFrom,
      to: options.to,
      subject: options.subject,
      html: html,
      text: text
    }, callback)
  })
}
774260
public function send($openId, $template, $url, array $data) {
        foreach ($data as $key => &$item) {
            if (!is_array($item)) {
                $item = [
                    'value' => $item,
                    'color' => '#777'
                ];
            }
        }
        $arg = $this->getSend()->parameters([
            'touser' => $openId,
            'template_id' => $template,
            'url' => $url,
            'data' => $data
        ])->json();
        return $arg['errcode'] == 0;
    }
315821
public function sendNewTaskEmailMessage(
        Task $task,
        UserInterface $createUser,
        UserInterface $assignUser,
        TypeInterface $type)
    {
        // $createUser, $recipientUser, $task, $link
        $template = $this->parameters['new_task']['template'];
        $from = $this->parameters['new_task']['from_email'];

        $text = $type->getText($task);
        $url = $type->getLink($task);

        $content = $this->templating->render(
            $template,
            [
                'createUser' => $createUser,
                'assignUser' => $assignUser,
                'task' => $task,
                'text' => $text,
                'url' => $url,
            ]
        );
        $this->sendEmailMessage($content, $from, $assignUser->getEmail());
    }
1232439
public function setCurrentTemplateEngine(string $id) {
		Container::getInstance()->setMulti($id, Container::MULTI_CLONE);
		$clazz = Container::getInstance()->get($id);
		if (!is_subclass_of($clazz, __NAMESPACE__ . '\\TemplateInterface')) {
			throw new InvalidClassException("$clazz not implemented TemplateInterface");
		}
		$this->tpl_engine_obj = $clazz;
	}
1168555
public function publishSystemTemplate($templateMessage) {
    	try{
			if (empty($templateMessage))
				throw new Exception('Paramer "templateMessage" is required');


    		$params = json_decode($templateMessage,TRUE);

    		$ret = $this->SendRequest->curl('/message/system/publish_template.json',$params,'json','im','POST');
    		if(empty($ret))
    			throw new Exception('bad request');
    		return $ret;

    	}catch (Exception $e) {
    		print_r($e->getMessage());
    	}
   }
359526
private function loadTemplate($templateId)
    {
        $template = $this->templateFactory->create();
        $this->templateResource->load($template, $templateId);

        return $template;
    }
311954
private function _sendNotification($aDiff, &$oRemoteApp, $aNewHistory)
        {

            // parse template
            $sHtml = $this->getContainer()->get('templating')->render('SlashworksAppBundle:Email:cron_notification.html.twig', array(
                'diff'       => $aDiff,
                'log'        => $aNewHistory['Log'],
                'remote_app' => $oRemoteApp,
                'controlurl' => $this->_getSiteURL()
            ));

            // get recipients
            $sRecipient = $oRemoteApp->getNotificationRecipient();
            // get sender
            $sSender = $oRemoteApp->getNotificationSender();

            // set subject and body of mail
            $sMessage = \Swift_Message::newInstance()->setSubject($this->getContainer()->get('translator')->trans('system.email.change.subject'))->setFrom($sSender)->setTo($sRecipient)->setContentType('text/html')->setBody($sHtml, 'text/html')->addPart($sHtml, 'text/html');

            // send email
            $this->getContainer()->get('mailer')->send($sMessage);
        }
1177026
def EmailTemplate(
        self,
        TemplateId,
        TemplateModel,
        From,
        To,
        TemplateAlias=None,
        Cc=None,
        Bcc=None,
        Subject=None,
        Tag=None,
        ReplyTo=None,
        Headers=None,
        TrackOpens=None,
        TrackLinks="None",
        Attachments=None,
        InlineCss=True,
    ):
        
        return EmailTemplate(
            manager=self,
            TemplateId=TemplateId,
            TemplateAlias=TemplateAlias,
            TemplateModel=TemplateModel,
            From=From,
            To=To,
            Cc=Cc,
            Bcc=Bcc,
            Subject=Subject,
            Tag=Tag,
            ReplyTo=ReplyTo,
            Headers=Headers,
            TrackOpens=TrackOpens,
            TrackLinks=TrackLinks,
            Attachments=Attachments,
            InlineCss=InlineCss,
        )