@@ -1266,6 +1266,57 @@ 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 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+ // src/Controller/DownloadEmailController.php
1285+ namespace App\Controller;
1286+
1287+ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1288+ use Symfony\Component\HttpFoundation\Response;
1289+ use Symfony\Component\HttpFoundation\ResponseHeaderBag;
1290+ use Symfony\Component\Mime\DraftEmail;
1291+ use Symfony\Component\Routing\Annotation\Route;
1292+
1293+ class DownloadEmailController extends AbstractController
1294+ {
1295+ #[Route('/download-email')]
1296+ public function __invoke(): Response
1297+ {
1298+ $message = (new DraftEmail())
1299+ ->html($this->renderView(/* ... */))
1300+ ->attach(/* ... */)
1301+ ;
1302+
1303+ $response = new Response($message->toString());
1304+ $contentDisposition = $response->headers->makeDisposition(
1305+ ResponseHeaderBag::DISPOSITION_ATTACHMENT,
1306+ 'download.eml'
1307+ );
1308+ $response->headers->set('Content-Type', 'message/rfc822');
1309+ $response->headers->set('Content-Disposition', $contentDisposition);
1310+
1311+ return $response;
1312+ }
1313+ }
1314+
1315+ .. note ::
1316+
1317+ As it's possible for :class: `Symfony\\ Component\\ Mime\\ DraftEmail `'s to be created
1318+ without a To/From they cannot be sent with the mailer.
1319+
12691320Development & Debugging
12701321-----------------------
12711322
0 commit comments