@@ -136,6 +136,20 @@ class Mailable implements MailableContract, Renderable
136136 */
137137 public $ diskAttachments = [];
138138
139+ /**
140+ * The tags for the message.
141+ *
142+ * @var array
143+ */
144+ protected $ tags = [];
145+
146+ /**
147+ * The metadata for the message.
148+ *
149+ * @var array
150+ */
151+ protected $ metadata = [];
152+
139153 /**
140154 * The callbacks for the message.
141155 *
@@ -190,6 +204,8 @@ public function send($mailer)
190204 $ this ->buildFrom ($ message )
191205 ->buildRecipients ($ message )
192206 ->buildSubject ($ message )
207+ ->buildTags ($ message )
208+ ->buildMetadata ($ message )
193209 ->runCallbacks ($ message )
194210 ->buildAttachments ($ message );
195211 });
@@ -449,6 +465,40 @@ protected function buildDiskAttachments($message)
449465 }
450466 }
451467
468+ /**
469+ * Add all defined tags to the message.
470+ *
471+ * @param \Illuminate\Mail\Message $message
472+ * @return $this
473+ */
474+ protected function buildTags ($ message )
475+ {
476+ if ($ this ->tags ) {
477+ foreach ($ this ->tags as $ tag ) {
478+ $ message ->getHeaders ()->add (new TagHeader ($ tag ));
479+ }
480+ }
481+
482+ return $ this ;
483+ }
484+
485+ /**
486+ * Add all defined metadata to the message.
487+ *
488+ * @param \Illuminate\Mail\Message $message
489+ * @return $this
490+ */
491+ protected function buildMetadata ($ message )
492+ {
493+ if ($ this ->metadata ) {
494+ foreach ($ this ->metadata as $ key => $ value ) {
495+ $ message ->getHeaders ()->add (new MetadataHeader ($ key , $ value ));
496+ }
497+ }
498+
499+ return $ this ;
500+ }
501+
452502 /**
453503 * Run the callbacks for the message.
454504 *
@@ -884,9 +934,9 @@ public function attachData($data, $name, array $options = [])
884934 */
885935 public function tag ($ value )
886936 {
887- return $ this ->withSymfonyMessage ( function ( Email $ message ) use ( $ value ) {
888- $ message -> getHeaders ()-> add ( new TagHeader ( $ value ));
889- }) ;
937+ array_push ( $ this ->tags , $ value );
938+
939+ return $ this ;
890940 }
891941
892942 /**
@@ -898,9 +948,9 @@ public function tag($value)
898948 */
899949 public function metadata ($ key , $ value )
900950 {
901- return $ this ->withSymfonyMessage ( function ( Email $ message ) use ( $ key , $ value) {
902- $ message -> getHeaders ()-> add ( new MetadataHeader ( $ key , $ value ));
903- }) ;
951+ $ this ->metadata [ $ key ] = $ value;
952+
953+ return $ this ;
904954 }
905955
906956 /**
0 commit comments