diff --git a/mail.md b/mail.md index 9ced46384c8..be9c61ef492 100644 --- a/mail.md +++ b/mail.md @@ -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) @@ -470,6 +471,27 @@ If you already have a raw image data string you wish to embed into an email temp ``` + +### 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. + ### Customizing The Symfony Message diff --git a/notifications.md b/notifications.md index e2ea7962859..51f2e33b490 100644 --- a/notifications.md +++ b/notifications.md @@ -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) @@ -526,6 +527,25 @@ The `attachData` method may be used to attach a raw string of bytes as an attach ]); } + +### 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); + } + ### Using Mailables