summaryrefslogtreecommitdiff
path: root/src/Mail
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-10-05 15:35:14 +0200
committermsquare <msquare@notrademark.de>2018-10-30 22:50:22 +0100
commit90e1a949623ead173c0952f802d7b5c5487251b1 (patch)
tree544d29dde573cb135b514d0a84c2d95e9207392c /src/Mail
parent0aa5f079258afd5276917c1aff565ec1c6411821 (diff)
Make application name configurable
* Added app_name configuration option * Extended `EngelsystemMailer` to prepend the application name to all mails Closes #426
Diffstat (limited to 'src/Mail')
-rw-r--r--src/Mail/EngelsystemMailer.php40
-rw-r--r--src/Mail/MailerServiceProvider.php3
2 files changed, 42 insertions, 1 deletions
diff --git a/src/Mail/EngelsystemMailer.php b/src/Mail/EngelsystemMailer.php
index 17047cc8..81660681 100644
--- a/src/Mail/EngelsystemMailer.php
+++ b/src/Mail/EngelsystemMailer.php
@@ -10,6 +10,13 @@ class EngelsystemMailer extends Mailer
/** @var Renderer|null */
protected $view;
+ /** @var string */
+ protected $subjectPrefix = null;
+
+ /**
+ * @param SwiftMailer $mailer
+ * @param Renderer $view
+ */
public function __construct(SwiftMailer $mailer, Renderer $view = null)
{
parent::__construct($mailer);
@@ -32,4 +39,37 @@ class EngelsystemMailer extends Mailer
return $this->send($to, $subject, $body);
}
+
+ /**
+ * Send the mail
+ *
+ * @param string|string[] $to
+ * @param string $subject
+ * @param string $body
+ * @return int
+ */
+ public function send($to, string $subject, string $body): int
+ {
+ if ($this->subjectPrefix) {
+ $subject = sprintf('[%s] %s', $this->subjectPrefix, $subject);
+ }
+
+ return parent::send($to, $subject, $body);
+ }
+
+ /**
+ * @return string
+ */
+ public function getSubjectPrefix(): string
+ {
+ return $this->subjectPrefix;
+ }
+
+ /**
+ * @param string $subjectPrefix
+ */
+ public function setSubjectPrefix(string $subjectPrefix)
+ {
+ $this->subjectPrefix = $subjectPrefix;
+ }
}
diff --git a/src/Mail/MailerServiceProvider.php b/src/Mail/MailerServiceProvider.php
index 989fee8f..70725afd 100644
--- a/src/Mail/MailerServiceProvider.php
+++ b/src/Mail/MailerServiceProvider.php
@@ -28,9 +28,10 @@ class MailerServiceProvider extends ServiceProvider
$this->app->instance(SwiftMailer::class, $swiftMailer);
$this->app->instance('mailer.swift', $swiftMailer);
- /** @var Mailer $mailer */
+ /** @var EngelsystemMailer $mailer */
$mailer = $this->app->make(EngelsystemMailer::class);
$mailer->setFromAddress($mailConfig['from']['address']);
+ $mailer->setSubjectPrefix($config->get('app_name'));
if (!empty($mailConfig['from']['name'])) {
$mailer->setFromName($mailConfig['from']['name']);
}