Files
coolify/app/Support/SmtpTransportFactory.php
T
Andras Bacsai f39c884cc7 fix(servers): support IPv6 server addresses everywhere
Store server IPs in one form (no brackets, short lower-case IPv6) and
write each address in the form its context needs:

- URLs and host:port (Sentinel, database URLs, SFTP backup download,
  DNS servers, SMTP, webhook base URLs, links, health checks) get
  brackets through formatHostForUrl().
- Traefik Host() rules use the address without brackets, so IPv6
  domains no longer return 404; saved labels are fixed at deploy.
  Caddy keeps the brackets.
- SSH keeps the plain address.
- Hetzner gives an IPv6 /64 network; IPv6-only servers now get the
  server address (prefix::1) instead of the unusable prefix::64.
- sslip labels, registry image names with an IPv6 host, the API domain
  list, allowlist matching and duplicate checks handle IPv6.

A migration normalizes stored IPv6 server addresses, repairs Hetzner
servers saved as ::64 that are not reachable, and adds brackets to
saved Sentinel URLs.
2026-10-09 13:50:28 +02:00

69 lines
2.0 KiB
PHP

<?php
namespace App\Support;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
class SmtpTransportFactory
{
public static function fromSettings(object $settings, ?string $localDomain = null): EsmtpTransport
{
$mode = self::encryptionMode($settings);
$transport = new EsmtpTransport(
formatHostForUrl((string) $settings->smtp_host),
(int) $settings->smtp_port,
match ($mode) {
'none' => false,
'tls' => true,
default => null,
}
);
if ($mode === 'none') {
$transport->setAutoTls(false);
}
$transport->setUsername($settings->smtp_username ?? '');
$transport->setPassword($settings->smtp_password ?? '');
$localDomain = $settings->smtp_ehlo_domain ?? $localDomain;
if ($localDomain !== null && $localDomain !== '') {
$transport->setLocalDomain($localDomain);
}
$stream = $transport->getStream();
if (isset($settings->smtp_timeout) && $stream instanceof SocketStream) {
$stream->setTimeout((float) $settings->smtp_timeout);
}
return $transport;
}
/**
* @return array{scheme: ?string, encryption: ?string, auto_tls: string}
*/
public static function mailerOptions(object $settings): array
{
$mode = self::encryptionMode($settings);
return [
'scheme' => match ($mode) {
'none', 'starttls' => 'smtp',
'tls' => 'smtps',
default => null,
},
'encryption' => $mode === 'tls' ? 'tls' : null,
'auto_tls' => $mode === 'none' ? '0' : '',
];
}
private static function encryptionMode(object $settings): ?string
{
return $settings->smtp_encryption === null
? null
: strtolower((string) $settings->smtp_encryption);
}
}