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