Skip to content

Commit

Permalink
Merge pull request #338 from prsnbrg/patch-1
Browse files Browse the repository at this point in the history
Fix: Mail sender name
  • Loading branch information
micbar authored Jun 21, 2021
2 parents 7e7e865 + a31b2aa commit 1e8a2c5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/Mailer/NotificationMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use OCP\Template;
use OCA\Notifications\Configuration\OptionsStorage;
use OCP\IURLGenerator;
use OCP\Defaults;
use OCP\Util;

/**
* The class will focus on sending notifications via email. In addition, some email-related
Expand All @@ -44,14 +46,40 @@ class NotificationMailer {

/** @var IURLGenerator */
private $urlGenerator;

/** @var string */
protected $senderAddress;

/** @var string */
protected $senderName;

public function __construct(IManager $manager, IMailer $mailer, OptionsStorage $optionsStorage, IURLGenerator $urlGenerator) {
$this->manager = $manager;
$this->mailer = $mailer;
$this->optionsStorage = $optionsStorage;
$this->urlGenerator = $urlGenerator;
}

/**
* Get the sender data
* @param string $setting Either `email` or `name`
* @return string
*/
protected function getSenderData($setting) {
if (empty($this->senderAddress)) {
$this->senderAddress = Util::getDefaultEmailAddress('no-reply');
}
if (empty($this->senderName)) {
$defaults = new Defaults();
$this->senderName = $defaults->getName();
}

if ($setting === 'email') {
return $this->senderAddress;
}
return $this->senderName;
}

/**
* Send a notification via email to the list of email addresses passed as parameter
* @param INotification $notification the notification to be sent
Expand All @@ -74,6 +102,7 @@ public function sendNotification(INotification $notification, $serverUrl, $email

$emailMessage = $this->mailer->createMessage();
$emailMessage->setTo([$emailAddress]);
$emailMessage->setFrom([$this->getSenderData('email') => $this->getSenderData('name')]);

$notificationLink = $notification->getLink();
$urlComponents = \parse_url($notificationLink);
Expand Down

0 comments on commit 1e8a2c5

Please sign in to comment.