Guest User

Untitled

a guest
Feb 18th, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <?php
  2. namespace Hevelop\Example\Console\Command;
  3. use Symfony\Component\Console\Command\Command;
  4. use Magento\Framework\Mail\TransportInterfaceFactory;
  5.  
  6. /**
  7. * Class SendMailWithoutTemplate
  8. */
  9. class SendMailWithoutTemplate extends Command
  10. {
  11. /**
  12. * @var TransportInterfaceFactory
  13. */
  14. protected $mailTransportFactory;
  15.  
  16. /**
  17. * @param ResourceConnection $dbConnection
  18. * @throws \LogicException
  19. */
  20. public function __construct(
  21. TransportInterfaceFactory $mailTransportFactory
  22. )
  23. {
  24. $this->mailTransportFactory = $mailTransportFactory;
  25. parent::__construct();
  26. }
  27.  
  28. /**
  29. * Configures the current command.
  30. * @throws \InvalidArgumentException
  31. */
  32. protected function configure()
  33. {
  34. $this->setName('example:sendmail')
  35. ->setDescription('Send a simple mail');
  36. parent::configure();
  37. }
  38.  
  39. public function execute()
  40. {
  41. $message = new \Magento\Framework\Mail\Message();
  42. $message->setFrom('mail.recipient@example.com');
  43. $message->addTo('mail.tosent@example.com');
  44. $message->setSubject('Subject');
  45. $message->setBody('Body');
  46. $transport = $this->mailTransportFactory->create(['message' => $message]);
  47. $transport->sendMessage();
  48. }
  49. }
Add Comment
Please, Sign In to add comment