Skip to content

Commit 279cac2

Browse files
author
Cari Spruiell
committed
Merge remote-tracking branch 'api/MAGETWO-52707-SMTP-Settings' into pull-request
2 parents ee0a116 + 719b2e8 commit 279cac2

File tree

2 files changed

+62
-0
lines changed

2 files changed

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

app/code/Magento/Email/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,7 @@
5757
</argument>
5858
</arguments>
5959
</type>
60+
<type name="Magento\Framework\Mail\TransportInterface">
61+
<plugin name="WindowsSmtpConfig" type="Magento\Email\Model\Plugin\WindowsSmtpConfig" />
62+
</type>
6063
</config>

0 commit comments

Comments
 (0)