# DownloadMailAction

> Streams a captured .eml file as an attachment, selected by its bare file name.

[API reference](/docs/api/index.md) › [Yii3 Debug](/docs/extensions/yii3-debug/reference/index.md) › [Action](/docs/extensions/yii3-debug/reference/action/index.md) › DownloadMailAction

| final readonly class | `Yii3\Debug\Action\DownloadMailAction` |
| --- | --- |
| Implements | [`DebugActionInterface`](/docs/extensions/yii3-debug/reference/action/debugactioninterface/index.md) |
| Source | [`src/Action/DownloadMailAction.php`](https://github.com/yii3/debug/blob/main/src/Action/DownloadMailAction.php#L18) |

Streams a captured `.eml` file as an attachment, selected by its bare file name.

A name carrying a path segment never resolves, so the endpoint serves only files the Mail collector stored.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates the download endpoint for `.eml` files resolved by the mail store. | `DownloadMailAction` |
| [`__invoke()`](#method-__invoke) | Streams the `.eml` file the `file` query parameter names. | `DownloadMailAction` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(Yii3\Debug\Mail\MailFileStore $files, Psr\Http\Message\ResponseFactoryInterface $responseFactory, Psr\Http\Message\StreamFactoryInterface $streamFactory)
```

Creates the download endpoint for `.eml` files resolved by the mail store.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$files` | [`Yii3\Debug\Mail\MailFileStore`](/docs/extensions/yii3-debug/reference/mail/mailfilestore/index.md) | Store resolving the requested file inside the mail directory. |
| `$responseFactory` | `Psr\Http\Message\ResponseFactoryInterface` | Factory building the PSR-7 response. |
| `$streamFactory` | `Psr\Http\Message\StreamFactoryInterface` | Factory building the PSR-7 response body. |

### __invoke() <span id="method-__invoke"></span>

```php
public function __invoke(Psr\Http\Message\ServerRequestInterface $request): Psr\Http\Message\ResponseInterface
```

Streams the `.eml` file the `file` query parameter names.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$request` | `Psr\Http\Message\ServerRequestInterface` | Incoming request carrying the query parameters. |

**Returns**

`Psr\Http\Message\ResponseInterface`: `message/rfc822` attachment, or a `404` response when the name is missing, unsafe, or unknown.