Skip to content

Commit 947a4a7

Browse files
kbondtaylorotwell
andauthored
[9.x] Add mail/notification tags & metadata docs (#7791)
* add mail/notification tags & metadata docs * formatting Co-authored-by: Taylor Otwell <[email protected]>
1 parent 3de884e commit 947a4a7

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

mail.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [View Data](#view-data)
1212
- [Attachments](#attachments)
1313
- [Inline Attachments](#inline-attachments)
14+
- [Tags & Metadata](#tags-and-metadata)
1415
- [Customizing The Symfony Message](#customizing-the-symfony-message)
1516
- [Markdown Mailables](#markdown-mailables)
1617
- [Generating Markdown Mailables](#generating-markdown-mailables)
@@ -470,6 +471,27 @@ If you already have a raw image data string you wish to embed into an email temp
470471
</body>
471472
```
472473

474+
<a name="tags-and-metadata"></a>
475+
### Tags & Metadata
476+
477+
Some third-party email providers such as Mailgun and Postmark support message "tags" and "metadata", which may be used to group and track emails sent by your application. You may add tags and metadata to an email message via the `tag` and `metadata` methods:
478+
479+
/**
480+
* Build the message.
481+
*
482+
* @return $this
483+
*/
484+
public function build()
485+
{
486+
return $this->view('emails.orders.shipped')
487+
->tag('shipment')
488+
->metadata('order_id', $this->order->id);
489+
}
490+
491+
If your application is using the Mailgun driver, you may consult Mailgun's documentation for more information on [tags](https://documentation.mailgun.com/en/latest/user_manual.html#tagging-1) and [metadata](https://documentation.mailgun.com/en/latest/user_manual.html#attaching-data-to-messages). Likewise, the Postmark documentation may also be consulted for more information on their support for [tags](https://postmarkapp.com/blog/tags-support-for-smtp) and [metadata](https://postmarkapp.com/support/article/1125-custom-metadata-faq).
492+
493+
If your application is using Amazon SES to send emails, you should use the `metadata` method to attach [SES "tags"](https://docs.aws.amazon.com/ses/latest/APIReference/API_MessageTag.html) to the message.
494+
473495
<a name="customizing-the-symfony-message"></a>
474496
### Customizing The Symfony Message
475497

notifications.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- [Customizing The Mailer](#customizing-the-mailer)
1717
- [Customizing The Templates](#customizing-the-templates)
1818
- [Attachments](#mail-attachments)
19+
- [Adding Tags & Metadata](#adding-tags-metadata)
1920
- [Using Mailables](#using-mailables)
2021
- [Previewing Mail Notifications](#previewing-mail-notifications)
2122
- [Markdown Mail Notifications](#markdown-mail-notifications)
@@ -526,6 +527,25 @@ The `attachData` method may be used to attach a raw string of bytes as an attach
526527
]);
527528
}
528529

530+
<a name="adding-tags-metadata"></a>
531+
### Adding Tags & Metadata
532+
533+
Tags and metadata can be added to the `MailMessage` - these are used by your email service for filtering/processing:
534+
535+
/**
536+
* Get the mail representation of the notification.
537+
*
538+
* @param mixed $notifiable
539+
* @return \Illuminate\Notifications\Messages\MailMessage
540+
*/
541+
public function toMail($notifiable)
542+
{
543+
return (new MailMessage)
544+
->greeting('Comment Upvoted!')
545+
->tag('upvote')
546+
->metadata('comment_id', $this->comment->id);
547+
}
548+
529549
<a name="using-mailables"></a>
530550
### Using Mailables
531551

0 commit comments

Comments
 (0)