Magento 2 – Send Custom Transactional Emails

magento2transactional-mail

As done in Magento 1.x.x, how can custom transactional emails be sent.

Additional

  • Add email in bcc

  • Send attachment along email

Best Answer

okie bit of debugging helps,

Sending a transactional email in Magento2

class Dummy
{

   /**
     * @var  \Magento\Framework\Mail\Template\TransportBuilder
     */
    private $_transportBuilder;

  public function __construct( \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder){

    $this->_transportBuilder = $transportBuilder;
  }

  public function sendEmail($templateId =1, $storeId =1,$templateParams)
  {

     $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)
            ->setTemplateOptions(['area' => Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])
            ->setTemplateVars($templateParams)
            ->setFrom('someemail@email.com')
            ->addTo('toemail@email.com')
            ->setReplyTo('replyto@email.com')
            ->addBcc('bcc@email.com')
            ->getTransport();
        $transport->sendMessage();
  }

}
Related Topic