8000 Allow custom sendmail command · symfony/symfony@7d3ba72 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7d3ba72

Browse files
committed
Allow custom sendmail command
1 parent 189ce09 commit 7d3ba72

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer_transports.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

7+
<parameters>
8+
<parameter key="mailer.sendmail_default_command">/usr/sbin/sendmail -bs</parameter>
9+
</parameters>
10+
711
<services>
812
<service id="mailer.transport_factory.abstract" class="Symfony\Component\Mailer\Transport\AbstractTransportFactory" abstract="true">
913
<argument type="service" id="event_dispatcher" />
@@ -41,6 +45,7 @@
4145

4246
<service id="mailer.transport_factory.sendmail" class="Symfony\Component\Mailer\Transport\SendmailTransportFactory" parent="mailer.transport_factory.abstract">
4347
<tag name="mailer.transport_factory" />
48+
<argument type="string">%mailer.sendmail_default_command%</argument>
4449
</service>
4550

4651
<service id="mailer.transport_factory.smtp" class="Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory" parent="mailer.transport_factory.abstract">

src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportFactoryTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,13 @@ public function createProvider(): iterable
3838
new Dsn('sendmail+smtp', 'default'),
3939
new SendmailTransport(null, $this->getDispatcher(), $this->getLogger()),
4040
];
41+
}
4142

42-
yield [
43-
Dsn::fromString('sendmail://default?command=/usr/local/bin/sendmail%20-t'),
44-
new SendmailTransport('/usr/local/bin/sendmail -t', $this->getDispatcher(), $this->getLogger()),
45-
];
46-
47-
yield [
48-
Dsn::fromString('sendmail://default?command=/usr/local/bin/sendmail+-t'),
49-
new SendmailTransport('/usr/local/bin/sendmail -t', $this->getDispatcher(), $this->getLogger()),
50-
];
43+
public function testCreateWithCustomCommand()
44+
{
45+
$factory = new SendmailTransportFactory($this->getDispatcher(), $this->getClient(), $this->getLogger(), '/usr/sbin/sendmail -t');
46+
$dsn = new Dsn('sendmail+smtp', 'default');
47+
$this->assertEquals(new SendmailTransport('/usr/sbin/sendmail -t', $this->getDispatcher(), $this->getLogger()), $factory->create($dsn));
5148
}
5249

5350
public function unsupportedSchemeProvider(): iterable

src/Symfony/Component/Mailer/Transport/SendmailTransportFactory.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,31 @@
1111

1212
namespace Symfony\Component\Mailer\Transport;
1313

14+
use Psr\Log\LoggerInterface;
1415
use Symfony\Component\Mailer\Exception\UnsupportedSchemeException;
16+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
17+
use Symfony\Contracts\HttpClient\HttpClientInterface;
1518

1619
/**
1720
* @author Konstantin Myakshin <molodchick@gmail.com>
1821
*/
1922
final class SendmailTransportFactory extends AbstractTransportFactory
2023
{
24+
/**
25+
* @var string
26+
*/
27+
private $command;
28+
29+
public function __construct(EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null, LoggerInterface $logger = null, ?string $command = null)
30+
{
31+
parent::__construct($dispatcher, $client, $logger);
32+
$this->command = $command;
33+
}
34+
2135
public function create(Dsn $dsn): TransportInterface
2236
{
2337
if ('sendmail+smtp' === $dsn->getScheme() || 'sendmail' === $dsn->getScheme()) {
24-
return new SendmailTransport($dsn->getOption('command'), $this->dispatcher, $this->logger);
38+
return new SendmailTransport($this->command, $this->dispatcher, $this->logger);
2539
}
2640

2741
throw new UnsupportedSchemeException($dsn, 'sendmail', $this->getSupportedSchemes());

0 commit comments

Comments
 (0)
0