Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain how to configure timeout in Readme #60

Merged
merged 2 commits into from
Aug 26, 2023
Merged
Changes from 1 commit
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
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Migrating from yiisoft/yii2-swiftmailer

To migrate from the deprecated [yiisoft/yii2-swiftmailer](https://github.com/yiisoft/yii2-swiftmailer) to this extension you need to update the application config.

Swiftmailer default transport was the `SendmailTransport`, while this extension will default to a `NullTransport` (sends no mail). You can use the swiftmailer default like the following:
Swiftmailer default transport was the `SendmailTransport`, while with this extension it will default to a `NullTransport` (sends no mail). You can use the swiftmailer default like the following:

```php
'mailer' => [
Expand All @@ -101,6 +101,47 @@ Swiftmailer default transport was the `SendmailTransport`, while this extension
],
],
```
With this extension, you do not have ability of directly setting timeout for example which with former extension could be set on configuration. The reason is, the underlying symfony extension defines its classes as final thereby discouraging inheritance and pushing towards composition. To achieve timeout (and other transport configurations), you will need to define factory class. below is a sample example for SMTP transport.

```php
namespace app\utils; //file is in utils folder of your application

use Symfony\Component\Messenger\Transport\TransportFactoryInterface;

class CustomSmtpFactory implements TransportFactoryInterface {
public function __construct(private TransportFactoryInterface $factory, private float $timeout)
{
$this->timeout = 120;
}

public function create(Dsn $dsn): TransportInterface
{
$result = $this->factory->create($dsn);
if ($result instanceof SmtpTransport) {
//Setup timeout to this or
$result->getStream()->setTimeout($this->timeout);
}
return $result;
}

public function supports(Dsn $dsn): bool {
return $this->factory->supports($dsn);
}
}
```

then in configuration, set the factory

```php
'mailer' => [
'class' => yii\symfonymailer\Mailer::class,
'transportFactory' => app\utils\CustomSmtpFactory::class,
'transport' => [
'scheme' => 'smtp',
//other settings
],
],
```

Security implications of the DSN
--------------------------------
Expand Down