Last active
October 6, 2020 14:05
-
-
Save vudaltsov/b86db743a11edba70946a3704399dea3 to your computer and use it in GitHub Desktop.
Symfony Mailer simple internal smpt transport
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAILER_DSN=insmtp://0.0.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | |
return static function (ContainerConfigurator $di): void { | |
$di | |
->services() | |
->set(InternalSmtpTransportFactory::class) | |
->autowire() | |
->tag('mailer.transport_factory') | |
; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
use Symfony\Component\Mailer\Transport\AbstractTransportFactory; | |
use Symfony\Component\Mailer\Transport\Dsn; | |
use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport; | |
use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream; | |
use Symfony\Component\Mailer\Transport\TransportInterface; | |
final class InternalSmtpTransportFactory extends AbstractTransportFactory | |
{ | |
public function create(Dsn $dsn): TransportInterface | |
{ | |
$stream = (new SocketStream()) | |
->setHost($dsn->getHost()) | |
->setPort($dsn->getPort() ?? 25) | |
->setStreamOptions([ | |
'ssl' => [ | |
'verify_peer' => false, | |
'verify_peer_name' => false, | |
], | |
]) | |
->disableTls() | |
; | |
return new SmtpTransport($stream, null, $this->logger); | |
} | |
protected function getSupportedSchemes(): array | |
{ | |
return ['insmtp']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment