Skip to content

Commit

Permalink
[9.x] Add mail/notification tags & metadata docs (#7791)
Browse files Browse the repository at this point in the history
* add mail/notification tags & metadata docs

* formatting

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
kbond and taylorotwell committed Mar 10, 2022
1 parent 3de884e commit 947a4a7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mail.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [View Data](#view-data)
- [Attachments](#attachments)
- [Inline Attachments](#inline-attachments)
- [Tags & Metadata](#tags-and-metadata)
- [Customizing The Symfony Message](#customizing-the-symfony-message)
- [Markdown Mailables](#markdown-mailables)
- [Generating Markdown Mailables](#generating-markdown-mailables)
Expand Down Expand Up @@ -470,6 +471,27 @@ If you already have a raw image data string you wish to embed into an email temp
</body>
```

<a name="tags-and-metadata"></a>
### Tags & Metadata

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:

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.orders.shipped')
->tag('shipment')
->metadata('order_id', $this->order->id);
}

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).

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.

<a name="customizing-the-symfony-message"></a>
### Customizing The Symfony Message

Expand Down
20 changes: 20 additions & 0 deletions notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- [Customizing The Mailer](#customizing-the-mailer)
- [Customizing The Templates](#customizing-the-templates)
- [Attachments](#mail-attachments)
- [Adding Tags & Metadata](#adding-tags-metadata)
- [Using Mailables](#using-mailables)
- [Previewing Mail Notifications](#previewing-mail-notifications)
- [Markdown Mail Notifications](#markdown-mail-notifications)
Expand Down Expand Up @@ -526,6 +527,25 @@ The `attachData` method may be used to attach a raw string of bytes as an attach
]);
}

<a name="adding-tags-metadata"></a>
### Adding Tags & Metadata

Tags and metadata can be added to the `MailMessage` - these are used by your email service for filtering/processing:

/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->greeting('Comment Upvoted!')
->tag('upvote')
->metadata('comment_id', $this->comment->id);
}

<a name="using-mailables"></a>
### Using Mailables

Expand Down

0 comments on commit 947a4a7

Please sign in to comment.