8000 [9.x] ability to add tags/metadata to Emails/Notifications by kbond · Pull Request #40783 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[9.x] ability to add tags/metadata to Emails/Notifications #40783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use PHPUnit\Framework\Assert as PHPUnit;
use ReflectionClass;
use ReflectionProperty;
use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mailer\Header\TagHeader;
use Symfony\Component\Mime\Email;

class Mailable implements MailableContract, Renderable
{
Expand Down Expand Up @@ -1021,6 +1024,33 @@ public function mailer($mailer)
return $this;
}

/**
* Add a tag to the email (for drivers that support).
*
* @param string $value
* @return $this
*/
public function tag($value)
{
return $this->withSymfonyMessage(function (Email $message) use ($value) {
8000 $message->getHeaders()->add(new TagHeader($value));
});
}

/**
* Add metadata to the email (for drivers that support).
*
* @param string $key
* @param string $value
* @return $this
*/
public function metadata($key, $value)
{
return $this->withSymfonyMessage(function (Email $message) use ($key, $value) {
$message->getHeaders()->add(new MetadataHeader($key, $value));
});
}

/**
* Register a callback to be called with the Symfony message instance.
*
Expand Down
30 changes: 30 additions & 0 deletions src/Illuminate/Notifications/Messages/MailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Mail\Markdown;
use Illuminate\Support\Traits\Conditionable;
use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mailer\Header\TagHeader;
use Symfony\Component\Mime\Email;

class MailMessage extends SimpleMessage implements Renderable
{
Expand Down Expand Up @@ -321,6 +324,33 @@ public function render()
->render($this->markdown, $this->data());
}

/**
* Add a tag to the email (for drivers that support).
*
* @param string $value
* @return $this
*/
public function tag($value)
{
return $this->withSymfonyMessage(function (Email $message) use ($value) {
$message->getHeaders()->add(new TagHeader($value));
});
}

/**
* Add metadata to the email (for drivers that support).
*
* @param string $key
* @param string $value
* @return $this
*/
public function metadata($key, $value)
{
return $this->withSymfonyMessage(function (Email $message) use ($key, $value) {
$message->getHeaders()->add(new MetadataHeader($key, $value));
});
}

/**
* Register a callback to be called with the Symfony message instance.
*
Expand Down
0