transportBuilder = $transportBuilder; $this->inlineTranslation = $inlineTranslation; $this->storeManager = $storeManager; $this->configHelper = $configHelper; $this->logger = $logger; } /** * Send report email * * @param string $csvContent * @param string $filename * @param string $month * @param string $year * @return bool */ public function sendReport($csvContent, $filename, $month = null, $year = null) { if (!$this->configHelper->isEmailEnabled()) { return false; } $recipients = $this->configHelper->getEmailRecipients(); if (empty($recipients)) { $this->logger->warning('Vendor Sales Report: No email recipients configured'); return false; } try { $this->inlineTranslation->suspend(); $sender = [ 'name' => $this->storeManager->getStore()->getName(), 'email' => $this->storeManager->getStore()->getConfig('trans_email/' . $this->configHelper->getEmailSender() . '/email') ]; $subject = $this->configHelper->getEmailSubject($month, $year); $transport = $this->transportBuilder ->setTemplateIdentifier('vendorsalesreport_email_template') ->setTemplateOptions([ 'area' => \Magento\Framework\App\Area::AREA_ADMINHTML, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, ]) ->setTemplateVars([ 'subject' => $subject, 'month' => $month, 'year' => $year ]) ->setFromByScope($sender) ->addTo($recipients) ->addAttachment($csvContent, $filename, 'text/csv') ->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); return true; } catch (\Exception $e) { $this->logger->error('Vendor Sales Report Email Error: ' . $e->getMessage()); $this->inlineTranslation->resume(); return false; } } }