Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/private/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,9 @@ protected function getInstance(): MailerInterface {
protected function getSmtpInstance(): EsmtpTransport {
// either null or true - if nothing is passed, let the symfony mailer figure out the configuration by itself
$mailSmtpsecure = ($this->config->getSystemValue('mail_smtpsecure', null) === 'ssl') ? true : null;
$mailSmtphost = $this->config->getSystemValueString('mail_smtphost', '127.0.0.1');
$transport = new EsmtpTransport(
$this->config->getSystemValueString('mail_smtphost', '127.0.0.1'),
$mailSmtphost,
$this->config->getSystemValueInt('mail_smtpport', 25),
$mailSmtpsecure,
null,
Expand All @@ -304,6 +305,17 @@ protected function getSmtpInstance(): EsmtpTransport {

$currentStreamingOptions = array_merge_recursive($currentStreamingOptions, $streamingOptions);

/** @psalm-suppress InternalMethod */
$stream->setStreamOptions($currentStreamingOptions);
} else if ($mailSmtphost === 'localhost' || $mailSmtphost === '127.0.0.1') {
Copy link
Contributor

@szaimen szaimen Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory we could even do this if no valid host was provided, e.g. by using such a filter: https://github.com/nextcloud/all-in-one/blob/c9b97220d0175914c3ee8c7199949376f7bfe3b0/php/src/Data/ConfigurationManager.php#L274-L295

However this sounds like magic and not sure if we want to actually do this automatically.

WDYT @nextcloud/server-backend @miaulalala

$currentStreamingOptions = $stream->getStreamOptions();
$currentStreamingOptions = array_merge_recursive($currentStreamingOptions, array(
'ssl' => array(
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false
)
));
Comment on lines +310 to +318
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm of two minds here - one is that it indeed makes localhosts work without any setup, which, as you stated has confused many users due to how the Symfony Mailer works. OTOH I'm not entirely happy with overwriting config options per default.

I think there's some middle ground here: check if the ssl option is set and only overwrite it if a) the host is localhost || 127.0.0.1 and b) if the option doesn't already exist in the $currentStreamingOptions

I also think it doesn't need to be an elseif but can be an if condition on it's own. Something like:

Suggested change
} else if ($mailSmtphost === 'localhost' || $mailSmtphost === '127.0.0.1') {
$currentStreamingOptions = $stream->getStreamOptions();
$currentStreamingOptions = array_merge_recursive($currentStreamingOptions, array(
'ssl' => array(
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false
)
));
}
$local = ['localhost', '127.0.0.1']; // You could make this a constant
if (in_array($mailSmtphost, $local) && !isset($currentStreamingOptions['ssl'])) {
$currentStreamingOptions = $stream->getStreamOptions();
$currentStreamingOptions = array_merge_recursive($currentStreamingOptions, array(
'ssl' => array(
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false
)
));

/** @psalm-suppress InternalMethod */
$stream->setStreamOptions($currentStreamingOptions);
}
Expand Down