WindowsSmtpConfig.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Email\Model\Plugin;
  7. /**
  8. * Plugin for \Magento\Framework\Mail\TransportInterface
  9. */
  10. class WindowsSmtpConfig
  11. {
  12. /**
  13. * host config path
  14. */
  15. const XML_SMTP_HOST = 'system/smtp/host';
  16. /**
  17. * port config path
  18. */
  19. const XML_SMTP_PORT = 'system/smtp/port';
  20. /**
  21. * @var \Magento\Framework\App\Config\ReinitableConfigInterface
  22. */
  23. private $config;
  24. /**
  25. * @var \Magento\Framework\OsInfo
  26. */
  27. private $osInfo;
  28. /**
  29. * @param \Magento\Framework\App\Config\ReinitableConfigInterface $config
  30. * @param \Magento\Framework\OsInfo $osInfo
  31. */
  32. public function __construct(
  33. \Magento\Framework\App\Config\ReinitableConfigInterface $config,
  34. \Magento\Framework\OsInfo $osInfo
  35. ) {
  36. $this->config = $config;
  37. $this->osInfo = $osInfo;
  38. }
  39. /**
  40. * To configure smtp settings for session right before sending message on windows server
  41. *
  42. * @param \Magento\Framework\Mail\TransportInterface $subject
  43. * @return void
  44. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  45. */
  46. public function beforeSendMessage(\Magento\Framework\Mail\TransportInterface $subject)
  47. {
  48. if ($this->osInfo->isWindows()) {
  49. ini_set('SMTP', $this->config->getValue(self::XML_SMTP_HOST));
  50. ini_set('smtp_port', $this->config->getValue(self::XML_SMTP_PORT));
  51. }
  52. }
  53. }