Skip to content

Commit c5f10c4

Browse files
committed
[Mime][Mailer] add DraftEmail documentation
1 parent b9a9936 commit c5f10c4

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

mailer.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,46 @@ The following transports only support tags:
12661266

12671267
* OhMySMTP
12681268

1269+
Draft Emails
1270+
------------
1271+
1272+
.. versionadded:: 6.1
1273+
1274+
``Symfony\Component\Mime\DraftEmail`` was introduced in ``symfony/mime`` 6.1.
1275+
1276+
:class:`Symfony\\Component\\Mime\\DraftEmail` is a special instance of
1277+
:class:`Symfony\\Component\\Mime\\Email`. Its purpose is to build up an email
1278+
(with body, attachments, etc) and make available to download as an ``.eml`` with
1279+
the ``X-Unsent`` header. Many email clients can open these files and interpret
1280+
them as *draft emails*. You can use these to create advanced ``mailto:`` links.
1281+
1282+
Here's an example of making one available to download::
1283+
1284+
use Symfony\Component\HttpFoundation\Response;
1285+
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
1286+
use Symfony\Component\Mime\DraftEmail;
1287+
1288+
$content = (new DraftEmail())
1289+
->html($twig->render(/* ... */))
1290+
->attach(/* ... */)
1291+
->toString()
1292+
;
1293+
1294+
$response = new Response($message->toString());
1295+
$contentDisposition = $response->headers->makeDisposition(
1296+
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
1297+
'download.eml'
1298+
);
1299+
$response->headers->set('Content-Type', 'message/rfc822');
1300+
$response->headers->set('Content-Disposition', $contentDisposition);
1301+
1302+
return $response;
1303+
1304+
.. note::
1305+
1306+
As it's possible for :class:`Symfony\\Component\\Mime\\DraftEmail`'s to be created
1307+
without a To/From they cannot be sent with the mailer.
1308+
12691309
Development & Debugging
12701310
-----------------------
12711311

0 commit comments

Comments
 (0)