Skip to content

Commit 82d8d19

Browse files
shyimpweyck
authored andcommitted
NEXT-15669 - Improve mail configuration
1 parent 14b301b commit 82d8d19

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Diff for: src/Core/Content/Mail/Service/MailerTransportFactory.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function create(?SystemConfigService $configService = null): TransportInt
5353
case 'smtp':
5454
return $this->createSmtpTransport($configService);
5555
case 'local':
56-
return new SendmailTransport('/usr/sbin/sendmail ' . ($configService->getString('core.mailerSettings.sendMailOptions') ?: '-bs'));
56+
return new SendmailTransport($this->getSendMailCommandLineArgument($configService));
5757
default:
5858
throw new \RuntimeException(sprintf('Invalid mail agent given "%s"', $emailAgent));
5959
}
@@ -86,4 +86,21 @@ private function getEncryption(SystemConfigService $configService): ?string
8686
return null;
8787
}
8888
}
89+
90+
private function getSendMailCommandLineArgument(SystemConfigService $configService): string
91+
{
92+
$command = '/usr/sbin/sendmail ';
93+
94+
$option = $configService->getString('core.mailerSettings.sendMailOptions');
95+
96+
if ($option === '') {
97+
$option = '-t';
98+
}
99+
100+
if ($option !== '-bs' && $option !== '-t') {
101+
throw new \RuntimeException(sprintf('Given sendmail option "%s" is invalid', $option));
102+
}
103+
104+
return $command . $option;
105+
}
89106
}

Diff for: src/Core/Content/Test/MailTemplate/Service/MailerTransportFactoryTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ public function testFactoryWithConfig(): void
7070

7171
static::assertEquals(\get_class($original), \get_class($mailer));
7272
}
73+
74+
public function testFactoryWithLocalAndInvalidConfig(): void
75+
{
76+
$original = new SendmailTransport();
77+
78+
$factory = $this->getContainer()->get('mailer.transport_factory');
79+
80+
static::expectException(\RuntimeException::class);
81+
static::expectExceptionMessage('Given sendmail option "-t && echo bla" is invalid');
82+
83+
$mailer = $factory->create(
84+
new ConfigService([
85+
'core.mailerSettings.emailAgent' => 'local',
86+
'core.mailerSettings.sendMailOptions' => '-t && echo bla',
87+
])
88+
);
89+
90+
static::assertEquals(\get_class($original), \get_class($mailer));
91+
}
7392
}
7493

7594
class ConfigService extends SystemConfigService

0 commit comments

Comments
 (0)