magento 2 add cc transportbuilder
<?php
/**
* MyCompany Email.
*/
namespace MyCompany\Email\Plugin;
use Magento\Framework\Mail\Template\TransportBuilder;
/**
* Class CcPlugin.
*/
class CcPlugin extends \Magento\Framework\Mail\Template\TransportBuilder
{
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* CcPlugin constructor.
*
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Psr\Log\LoggerInterface $logger
) {
$this->scopeConfig = $scopeConfig;
$this->logger = $logger;
}
/**
* Set cc for transactional emails, if configured via admin.
*/
public function beforeGetTransport(TransportBuilder $subject)
{
try {
$path = 'email/general/cc';
if ($this->scopeConfig) {
$ccEmailAddress = $this->scopeConfig->getValue(
$path,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
if (!empty($ccEmailAddress)) {
$subject->addCc($ccEmailAddress);
}
}
} catch (\Exception $e) {
$this->logger->error('Failure in MyCompany Cc module: ' . $e->getMessage());
}
return [];
}
}