File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -1266,6 +1266,46 @@ The following transports only support tags:
1266
1266
1267
1267
* OhMySMTP
1268
1268
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
+
1269
1309
Development & Debugging
1270
1310
-----------------------
1271
1311
You can’t perform that action at this time.
0 commit comments