class MailManager implements Factory mixin Mailer

Traits

Constants

protected TRANSPORT_PRESENTATION_KEYS

Mailer-level keys that do not affect built-in transport construction.

Properties

protected Closure> $releaseCallbacks from  HasPoolProxy
protected Repository $config

The config instance.

protected array $mailers

The array of resolved mailers.

protected array $customCreators

The registered custom driver creators.

protected array $poolables

The array of drivers which will be wrapped as pool proxies.

Methods

mixed
createPoolProxy(string $driver, Closure $resolver, PoolDefinition $definition, string $proxyClass)

Create a pool proxy for an immutable definition.

poolDefinition(string $resource, array $poolConfig, array $fingerprintSource)

Build a namespaced pool definition for a pooled resource.

poolFactory()

Get the shared object-pool factory.

setReleaseCallback(string $driver, Closure $callback)

Set the release callback for a pooled driver.

Closure|null
getReleaseCallback(string $driver)

Get the release callback for a pooled driver.

addPoolable(string $driver)

Add a driver to the poolable-driver list.

removePoolable(string $driver)

Remove a driver from the poolable-driver list.

array
getPoolables()

Get the poolable-driver list.

setPoolables(array $poolables)

Set the poolable-driver list.

__construct(Container $app)

Create a new Mail manager instance.

mailer(UnitEnum|string|null $name = null)

Get a mailer instance by name.

driver(UnitEnum|string|null $driver = null)

Get a mailer driver instance.

get(string $name)

Attempt to get the mailer from the local cache.

resolve(string $name)

Resolve the given mailer.

build(array $config)

Build a new mailer instance.

TransportInterface
createSymfonyTransport(array $config)

Create a new transport instance.

TransportInterface
createMailerTransport(array $config, array $mailerStack = [], bool $poolByDefault = false)

Create a pooled or direct transport for a mailer.

array|null
transportPoolConfig(string $transport, array $config, bool $poolByDefault)

Resolve whether and how a mail transport should be pooled.

TransportInterface
createSymfonyTransportFromConstructionConfig(array $config)

Create a transport from its fully resolved construction config.

array
transportConstructionConfig(array $config, array $mailerStack = [])

Resolve the exact configuration consumed to construct a transport.

array
mailgunTransportConstructionConfig(array $config)

Resolve Mailgun's credential and HTTP-client construction config.

array
compositeTransportConstructionConfig(string $transport, array $config, array $mailerStack)

Resolve a composite transport's ordered child construction configs.

array
httpClientConstructionConfig(array $config)

Extract HTTP-client options that affect transport construction.

EsmtpTransport
createSmtpTransport(array $config)

Create an instance of the Symfony SMTP Transport driver.

EsmtpTransport
configureSmtpTransport(EsmtpTransport $transport, array $config)

Configure the additional SMTP driver options.

SendmailTransport
createSendmailTransport(array $config)

Create an instance of the Symfony Sendmail Transport driver.

createSesV2Transport(array $config)

Create an instance of the Symfony Amazon SES V2 Transport driver.

array
addSesCredentials(array $config)

Add the SES credentials to the configuration array.

createResendTransport(array $config)

Create an instance of the Resend Transport driver.

createCloudflareTransport(array $config)

Create an instance of the Cloudflare Transport driver.

SendmailTransport
createMailTransport()

Create an instance of the Symfony Mail Transport driver.

TransportInterface
createMailgunTransport(array $config)

Create an instance of the Symfony Mailgun Transport driver.

PostmarkApiTransport
createPostmarkTransport(array $config)

Create an instance of the Symfony Postmark Transport driver.

FailoverTransport
createFailoverTransport(array $config)

Create an instance of the Symfony Failover Transport driver.

RoundRobinTransport
createRoundrobinTransport(array $config)

Create an instance of the Symfony Roundrobin Transport driver.

RoundRobinTransport
createRoundrobinTransportOfClass(array $config, string $class)

Create an instance of supplied class extending the Symfony Roundrobin Transport driver.

createLogTransport(array $config)

Create an instance of the Log Transport driver.

createArrayTransport()

Create an instance of the Array Transport Driver.

HttpClientInterface|null
getHttpClient(array $config)

Get a configured Symfony HTTP client instance.

void
setGlobalAddress(Mailer $mailer, array $config, string $type)

Set a global address on the mailer by type.

array|null
getConfig(string $name)

Get the mail connection configuration.

string
getDefaultDriver()

Get the default mail driver name.

void
setDefaultDriver(UnitEnum|string $name)

Set the default mail driver name.

void
purge(UnitEnum|string|null $name = null)

Disconnect the given mailer and close its shared transport pool.

extend(string $driver, Closure $callback, bool $poolable = false)

Register a custom driver creator Closure.

getApplication()

Get the application instance used by the manager.

setApplication(Container $app)

Set the application instance used by the manager.

forgetMailers()

Forget all of the resolved mailer instances.

__call(string $method, array $parameters)

Dynamically call the default driver instance.

Details

in HasPoolProxy at line 24
protected mixed createPoolProxy(string $driver, Closure $resolver, PoolDefinition $definition, string $proxyClass)

Create a pool proxy for an immutable definition.

Parameters

string $driver
Closure $resolver
PoolDefinition $definition
string $proxyClass

Return Value

mixed

in HasPoolProxy at line 45
protected PoolDefinition poolDefinition(string $resource, array $poolConfig, array $fingerprintSource)

Build a namespaced pool definition for a pooled resource.

Parameters

string $resource
array $poolConfig
array $fingerprintSource

Return Value

PoolDefinition

at line 672
protected Factory poolFactory()

Get the shared object-pool factory.

Return Value

Factory

in HasPoolProxy at line 71
HasPoolProxy setReleaseCallback(string $driver, Closure $callback)

Set the release callback for a pooled driver.

Boot-only. The callback persists on the manager for the worker lifetime and is captured by every subsequently created proxy for the driver.

Parameters

string $driver
Closure $callback

Return Value

HasPoolProxy

in HasPoolProxy at line 81
Closure|null getReleaseCallback(string $driver)

Get the release callback for a pooled driver.

Parameters

string $driver

Return Value

Closure|null

in HasPoolProxy at line 93
HasPoolProxy addPoolable(string $driver)

Add a driver to the poolable-driver list.

Boot-only. The list persists on the manager for the worker lifetime and is consulted on subsequent driver creation. Per-request use races across coroutines and does not affect already-cached drivers.

Parameters

string $driver

Return Value

HasPoolProxy

in HasPoolProxy at line 109
HasPoolProxy removePoolable(string $driver)

Remove a driver from the poolable-driver list.

Boot-only. The list persists on the manager for the worker lifetime and is consulted on subsequent driver creation. Per-request use races across coroutines and does not affect already-cached drivers.

Parameters

string $driver

Return Value

HasPoolProxy

in HasPoolProxy at line 126
array getPoolables()

Get the poolable-driver list.

Return Value

array

in HasPoolProxy at line 138
HasPoolProxy setPoolables(array $poolables)

Set the poolable-driver list.

Boot-only. The list persists on the manager for the worker lifetime and is consulted on subsequent driver creation. Per-request use races across coroutines and does not affect already-cached drivers.

Parameters

array $poolables

Return Value

HasPoolProxy

at line 86
__construct(Container $app)

Create a new Mail manager instance.

Parameters

Container $app

at line 95
Mailer mailer(UnitEnum|string|null $name = null)

Get a mailer instance by name.

Parameters

UnitEnum|string|null $name

Return Value

Mailer

at line 111
Mailer driver(UnitEnum|string|null $driver = null)

Get a mailer driver instance.

Parameters

UnitEnum|string|null $driver

Return Value

Mailer

at line 119
protected Mailer get(string $name)

Attempt to get the mailer from the local cache.

Parameters

string $name

Return Value

Mailer

at line 129
protected Mailer resolve(string $name)

Resolve the given mailer.

Parameters

string $name

Return Value

Mailer

Exceptions

InvalidArgumentException

at line 164
Mailer build(array $config)

Build a new mailer instance.

Parameters

array $config

Return Value

Mailer

at line 185
TransportInterface createSymfonyTransport(array $config)

Create a new transport instance.

Parameters

array $config

Return Value

TransportInterface

Exceptions

InvalidArgumentException

at line 197
protected TransportInterface createMailerTransport(array $config, array $mailerStack = [], bool $poolByDefault = false)

Create a pooled or direct transport for a mailer.

Parameters

array $config
array $mailerStack
bool $poolByDefault

Return Value

TransportInterface

at line 221
protected array|null transportPoolConfig(string $transport, array $config, bool $poolByDefault)

Resolve whether and how a mail transport should be pooled.

Parameters

string $transport
array $config
bool $poolByDefault

Return Value

array|null

at line 251
protected TransportInterface createSymfonyTransportFromConstructionConfig(array $config)

Create a transport from its fully resolved construction config.

Parameters

array $config

Return Value

TransportInterface

at line 270
protected array transportConstructionConfig(array $config, array $mailerStack = [])

Resolve the exact configuration consumed to construct a transport.

Parameters

array $config
array $mailerStack

Return Value

array

at line 343
protected array mailgunTransportConstructionConfig(array $config)

Resolve Mailgun's credential and HTTP-client construction config.

Parameters

array $config

Return Value

array

at line 365
protected array compositeTransportConstructionConfig(string $transport, array $config, array $mailerStack)

Resolve a composite transport's ordered child construction configs.

Parameters

string $transport
array $config
array $mailerStack

Return Value

array

at line 407
protected array httpClientConstructionConfig(array $config)

Extract HTTP-client options that affect transport construction.

Parameters

array $config

Return Value

array

at line 415
protected EsmtpTransport createSmtpTransport(array $config)

Create an instance of the Symfony SMTP Transport driver.

Parameters

array $config

Return Value

EsmtpTransport

at line 441
protected EsmtpTransport configureSmtpTransport(EsmtpTransport $transport, array $config)

Configure the additional SMTP driver options.

Parameters

EsmtpTransport $transport
array $config

Return Value

EsmtpTransport

at line 461
protected SendmailTransport createSendmailTransport(array $config)

Create an instance of the Symfony Sendmail Transport driver.

Parameters

array $config

Return Value

SendmailTransport

at line 469
protected SesV2Transport createSesV2Transport(array $config)

Create an instance of the Symfony Amazon SES V2 Transport driver.

Parameters

array $config

Return Value

SesV2Transport

at line 482
protected array addSesCredentials(array $config)

Add the SES credentials to the configuration array.

Parameters

array $config

Return Value

array

at line 498
protected ResendTransport createResendTransport(array $config)

Create an instance of the Resend Transport driver.

Parameters

array $config

Return Value

ResendTransport

at line 506
protected CloudflareTransport createCloudflareTransport(array $config)

Create an instance of the Cloudflare Transport driver.

Parameters

array $config

Return Value

CloudflareTransport

at line 518
protected SendmailTransport createMailTransport()

Create an instance of the Symfony Mail Transport driver.

Return Value

SendmailTransport

at line 526
protected TransportInterface createMailgunTransport(array $config)

Create an instance of the Symfony Mailgun Transport driver.

Parameters

array $config

Return Value

TransportInterface

at line 543
protected PostmarkApiTransport createPostmarkTransport(array $config)

Create an instance of the Symfony Postmark Transport driver.

Parameters

array $config

Return Value

PostmarkApiTransport

at line 564
protected FailoverTransport createFailoverTransport(array $config)

Create an instance of the Symfony Failover Transport driver.

Parameters

array $config

Return Value

FailoverTransport

at line 572
protected RoundRobinTransport createRoundrobinTransport(array $config)

Create an instance of the Symfony Roundrobin Transport driver.

Parameters

array $config

Return Value

RoundRobinTransport

at line 587
protected RoundRobinTransport createRoundrobinTransportOfClass(array $config, string $class)

Create an instance of supplied class extending the Symfony Roundrobin Transport driver.

Parameters

array $config
string $class

Return Value

RoundRobinTransport

Exceptions

InvalidArgumentException

at line 601
protected LogTransport createLogTransport(array $config)

Create an instance of the Log Transport driver.

Parameters

array $config

Return Value

LogTransport

at line 615
protected ArrayTransport createArrayTransport()

Create an instance of the Array Transport Driver.

Return Value

ArrayTransport

at line 625
protected HttpClientInterface|null getHttpClient(array $config)

Get a configured Symfony HTTP client instance.

Parameters

array $config

Return Value

HttpClientInterface|null

at line 644
protected void setGlobalAddress(Mailer $mailer, array $config, string $type)

Set a global address on the mailer by type.

Parameters

Mailer $mailer
array $config
string $type

Return Value

void

at line 656
protected array|null getConfig(string $name)

Get the mail connection configuration.

Parameters

string $name

Return Value

array|null

at line 680
string getDefaultDriver()

Get the default mail driver name.

Return Value

string

at line 690
void setDefaultDriver(UnitEnum|string $name)

Set the default mail driver name.

Boot-only. Mutates process-global config; per-request use races across coroutines.

Parameters

UnitEnum|string $name

Return Value

void

at line 704
void purge(UnitEnum|string|null $name = null)

Disconnect the given mailer and close its shared transport pool.

Boot or tests only, plus operational recovery of broken pooled resources. Other mailers sharing the pool transparently acquire a fresh pool on their next operation.

Parameters

UnitEnum|string|null $name

Return Value

void

at line 756
MailManager extend(string $driver, Closure $callback, bool $poolable = false)

Register a custom driver creator Closure.

Boot-only. The callback persists in the singleton's customCreators array (and the poolable list if $poolable is true) for the worker lifetime and applies to every subsequent transport resolution.

Parameters

string $driver
Closure $callback
bool $poolable

Return Value

MailManager

at line 770
Container getApplication()

Get the application instance used by the manager.

Return Value

Container

at line 781
MailManager setApplication(Container $app)

Set the application instance used by the manager.

Tests only. Swaps the singleton's container reference; per-request use races across coroutines and breaks every concurrent mail send.

Parameters

Container $app

Return Value

MailManager

at line 794
MailManager forgetMailers()

Forget all of the resolved mailer instances.

Boot or tests only. This is cache-only: pooled transports remain shared resources until purged or reclaimed by their idle TTL.

Return Value

MailManager

at line 804
__call(string $method, array $parameters)

Dynamically call the default driver instance.

Parameters

string $method
array $parameters